- 浏览: 551457 次
- 性别:
- 来自: 南京
文章分类
- 全部博客 (350)
- Sybase (30)
- SQL SERVER2005 (14)
- 数据库 (27)
- SSH框架 (27)
- WebService (21)
- 下载-软件收藏 (15)
- 随笔-日常使用 (9)
- Flex 相关 (13)
- Linux (11)
- Web (64)
- XML相关 (9)
- Socket相关 (1)
- Elipse (3)
- 统计报表 (11)
- 线程相关 (3)
- Java相关 (37)
- JAVASCRIPT (19)
- JAVA反射 (3)
- JSP标签 (3)
- 随笔-其他 (2)
- 随笔-设计模式 (3)
- 随笔-架构师相关 (1)
- 下载-源码 (7)
- 下载-帮助文档 (1)
- 下载-插件 (6)
- 技术-.NET (2)
- 技术-Excel VBA (8)
- 应用-地图相关 (2)
- 应用-GSM短信猫 (5)
- 应用-单点登录 (3)
- Android相关 (3)
最新评论
-
sucheng2016:
发现jconn4.jar 里面有getBlob(String) ...
Sybase15驱动包的问题com.sybase.jdbc3.jdbc.SybDriver -
sucheng2016:
java.lang.UnsupportedOperationE ...
Sybase15驱动包的问题com.sybase.jdbc3.jdbc.SybDriver -
ok123zxx:
没下文了吗
通过 Tomcat Advanced I/O 获得高性能的 Ajax tocmat6+CometProcessor -
q1345111:
大家这个问题 尚未完成方法 com.sybase.jdbc3. ...
Sybase15驱动包的问题com.sybase.jdbc3.jdbc.SybDriver -
bdk82924:
heshujing217187 写道问题同1楼一样,求解!换j ...
Sybase15驱动包的问题com.sybase.jdbc3.jdbc.SybDriver
Java实现 栈(stack)与堆(heap)
上次写过一个的,下次记得把代码贴上来
待续...
HeapUtil
StackUtil
Test
MyVec 是我写的另外一个例子
特殊的缓存列表 首先有500的缓存大小用来入数据, 10缓存的大小用来读取数据, 读完后指针及指向后面了
上次写过一个的,下次记得把代码贴上来
待续...
HeapUtil
import java.util.EmptyStackException; import java.util.Vector; /** * * 模拟 堆,先进先出 * * @author * @date 2012-6-27 上午02:19:06 * * @version 1.0 */ public class HeapUtil<E> extends Vector<E> { /** * Creates an empty Stack. */ public HeapUtil() { } /** * Pushes an item onto the top of this stack. This has exactly the same * effect as: <blockquote> * * <pre> * addElement(item) * </pre> * * </blockquote> * * @param item * the item to be pushed onto this stack. * @return the <code>item</code> argument. * @see java.util.Vector#addElement */ public E push(E item) { addElement(item); return item; } /** * Removes the object at the top of this stack and returns that object as * the value of this function. * * @return The object at the top of this stack (the last item of the * <tt>Vector</tt> object). * @exception EmptyStackException * if this stack is empty. */ public synchronized E pop() { if (empty()) { return null; } E obj; int len = size(); obj = peek(); removeElementAt(0); return obj; } /** * Looks at the object at the top of this stack without removing it from the * stack. * * @return the object at the top of this stack (the last item of the * <tt>Vector</tt> object). * @exception EmptyStackException * if this stack is empty. */ public synchronized E peek() { int len = size(); if (len == 0) throw new EmptyStackException(); return elementAt(0); } /** * Tests if this stack is empty. * * @return <code>true</code> if and only if this stack contains no items; * <code>false</code> otherwise. */ public boolean empty() { return size() == 0; } /** * Returns the 1-based position where an object is on this stack. If the * object <tt>o</tt> occurs as an item in this stack, this method returns * the distance from the top of the stack of the occurrence nearest the top * of the stack; the topmost item on the stack is considered to be at * distance <tt>1</tt>. The <tt>equals</tt> method is used to compare * <tt>o</tt> to the items in this stack. * * @param o * the desired object. * @return the 1-based position from the top of the stack where the object * is located; the return value <code>-1</code> indicates that the * object is not on the stack. */ public synchronized int search(Object o) { int i = lastIndexOf(o); if (i >= 0) { return size() - i; } return -1; } /** use serialVersionUID from JDK 1.0.2 for interoperability */ private static final long serialVersionUID = 1224463164541339165L; }
StackUtil
/** * * 栈 先进后出 * * @author * @date 2012-6-27 上午08:36:52 * * @param <E> * @version 1.0 */ public class StackUtil<E> extends Vector<E> { /** * Creates an empty Stack. */ public StackUtil() { } /** * Pushes an item onto the top of this stack. This has exactly the same * effect as: <blockquote> * * <pre> * addElement(item) * </pre> * * </blockquote> * * @param item * the item to be pushed onto this stack. * @return the <code>item</code> argument. * @see java.util.Vector#addElement */ public E push(E item) { addElement(item); return item; } /** * Removes the object at the top of this stack and returns that object as * the value of this function. * * @return The object at the top of this stack (the last item of the * <tt>Vector</tt> object). * @exception EmptyStackException * if this stack is empty. */ public synchronized E pop() { if (empty()) { return null; } E obj; int len = size(); obj = peek(); removeElementAt(len - 1); return obj; } /** * Looks at the object at the top of this stack without removing it from the * stack. * * @return the object at the top of this stack (the last item of the * <tt>Vector</tt> object). * @exception EmptyStackException * if this stack is empty. */ public synchronized E peek() { int len = size(); if (len == 0) throw new EmptyStackException(); return elementAt(len - 1); } /** * Tests if this stack is empty. * * @return <code>true</code> if and only if this stack contains no items; * <code>false</code> otherwise. */ public boolean empty() { return size() == 0; } /** * Returns the 1-based position where an object is on this stack. If the * object <tt>o</tt> occurs as an item in this stack, this method returns * the distance from the top of the stack of the occurrence nearest the top * of the stack; the topmost item on the stack is considered to be at * distance <tt>1</tt>. The <tt>equals</tt> method is used to compare * <tt>o</tt> to the items in this stack. * * @param o * the desired object. * @return the 1-based position from the top of the stack where the object * is located; the return value <code>-1</code> indicates that the * object is not on the stack. */ public synchronized int search(Object o) { int i = lastIndexOf(o); if (i >= 0) { return size() - i; } return -1; } /** use serialVersionUID from JDK 1.0.2 for interoperability */ private static final long serialVersionUID = 1224463164541339165L; }
Test
import java.util.Arrays; public class Test { public static void main(String[] args) { MyVec<Integer> m = new MyVec<Integer>(5); m.push(1); m.push(2); m.push(3); m.push(4); m.push(5); System.out.println(Arrays.asList(m.get())); System.out.println(Arrays.asList(m.get())); System.out.println(Arrays.asList(m.get())); System.out.println(Arrays.asList(m.get())); System.out.println(Arrays.asList(m.get())); m.push(6); m.push(7); m.push(8); System.out.println(Arrays.asList(m.get())); m.push(9); m.push(10); System.out.println(Arrays.asList(m.get())); System.out.println(Arrays.asList(m.get())); System.out.println(Arrays.asList(m.get())); System.out.println(Arrays.asList(m.get())); // while (!m.empty()) // { // System.out.println(m.pop()); // } } public static void main1(String[] args) { System.out.println("StackUtil......"); StackUtil<String> s = new StackUtil<String>(); s.push("1"); s.push("2"); s.push("3"); while (!s.empty()) { System.out.println(s.pop()); } System.out.println("HeapUtil......"); HeapUtil<String> h = new HeapUtil<String>(); h.push("1"); h.push("2"); h.push("3"); while (!h.empty()) { System.out.println(h.pop()); } System.out.println("QueueUtil......"); QueueUtil<String> q = new QueueUtil<String>(); q.add("1"); q.add("2"); q.add("3"); for (int i = 0; i < 10; i++) { System.out.println(q.next()); } } }
MyVec 是我写的另外一个例子
特殊的缓存列表 首先有500的缓存大小用来入数据, 10缓存的大小用来读取数据, 读完后指针及指向后面了
import java.util.ArrayList; import java.util.EmptyStackException; import java.util.List; import java.util.Vector; /** * * 特殊的缓存列表 首先有500的缓存大小用来入数据, 10缓存的大小用来读取数据, 读完后指针及指向后面了, * * @author bdk197431 * @date 2013-1-14 上午12:41:00 * * @version 1.0 */ public class MyVec<E> extends Vector<E> { /** * 总大小,缓存的申请大小,如500 */ private int maxSize; /** * 读取缓存的大小,如10,这个值要小于maxSize */ private int readBuffMaxSize = 2; /** * 指针的指向的id */ private int startIndex; /** * 指针的指向的endId */ private int endIndex; public MyVec() { } public MyVec(int maxSize) { this.maxSize = maxSize; } public void debug(String s) { // System.out.println(s); } public String toString() { StringBuilder sb = new StringBuilder(); sb.append("["); for (int i = 0; i < size(); i++) { sb.append(elementAt(i)); if (i != size() - 1) { sb.append(","); } } sb.append("]"); return sb.toString(); } public List<E> get() { debug("get"); List<E> list = new ArrayList<E>(); for (int i = startIndex; i < endIndex; i++) { list.add(get(i)); } if (startIndex + readBuffMaxSize > endIndex) { startIndex = endIndex; } else { startIndex += readBuffMaxSize; endIndex += readBuffMaxSize; } if (endIndex >= maxSize) { endIndex = maxSize; } // readBuffSize = 0; debug("start:" + startIndex + " end:" + endIndex); debug(this.toString()); return list; } public E get(int index) { if (index >= this.maxSize && index <= endIndex) { index = index % this.maxSize; } return elementAt(index); } /** * * 增加 读取缓存的大小 * * @author * @date 2013-1-14 上午03:22:11 */ private void addReadBuffSize() { endIndex++; if (endIndex - startIndex > readBuffMaxSize) { endIndex = startIndex + readBuffMaxSize; } if (startIndex > 0) { moveIndex(-1); } } private void moveIndex(int num) { startIndex += num; endIndex += num; if (endIndex > maxSize) { moveIndex(-1); } } /** * Pushes an item onto the top of this stack. This has exactly the same * effect as: <blockquote> * * <pre> * addElement(item) * </pre> * * </blockquote> * * @param item * the item to be pushed onto this stack. * @return the <code>item</code> argument. * @see java.util.Vector#addElement */ public E push(E item) { debug("push"); addElement(item); if (this.size() > maxSize) { removeElementAt(0); // 指针整体移动一位 moveIndex(1); } addReadBuffSize(); debug("start:" + startIndex + " end:" + endIndex); return item; } /** * Removes the object at the top of this stack and returns that object as * the value of this function. * * @return The object at the top of this stack (the last item of the * <tt>Vector</tt> object). * @exception EmptyStackException * if this stack is empty. */ public synchronized E pop() { if (empty()) { return null; } E obj; int len = size(); obj = peek(); removeElementAt(len - 1); return obj; } /** * Looks at the object at the top of this stack without removing it from the * stack. * * @return the object at the top of this stack (the last item of the * <tt>Vector</tt> object). * @exception EmptyStackException * if this stack is empty. */ public synchronized E peek() { int len = size(); if (len == 0) throw new EmptyStackException(); return elementAt(len - 1); } /** * Tests if this stack is empty. * * @return <code>true</code> if and only if this stack contains no items; * <code>false</code> otherwise. */ public boolean empty() { return size() == 0; } /** * Returns the 1-based position where an object is on this stack. If the * object <tt>o</tt> occurs as an item in this stack, this method returns * the distance from the top of the stack of the occurrence nearest the top * of the stack; the topmost item on the stack is considered to be at * distance <tt>1</tt>. The <tt>equals</tt> method is used to compare * <tt>o</tt> to the items in this stack. * * @param o * the desired object. * @return the 1-based position from the top of the stack where the object * is located; the return value <code>-1</code> indicates that the * object is not on the stack. */ public synchronized int search(Object o) { int i = lastIndexOf(o); if (i >= 0) { return size() - i; } return -1; } /** use serialVersionUID from JDK 1.0.2 for interoperability */ private static final long serialVersionUID = 1224463164541339165L; }
发表评论
-
Jav解析soap的xml
2015-05-17 21:13 748解析xml import org.dom4j.Docume ... -
Json转换利器Gson
2013-12-13 08:59 491转: http://blog.csdn.net/lk_blog ... -
asm jar包冲突的问题和解决方法(转)
2013-11-03 01:48 1076asm jar包冲突的问题和解决方法 在用Spring+Hi ... -
Spring ehCache 示例
2013-04-28 15:46 749http://blog.chinaunix.net/uid-2 ... -
将json字符串转换为bean (json-lib)
2013-04-26 15:26 972Json-lib可以将Java对象转成json格式的字符串,也 ... -
QPID学习
2013-03-09 14:13 4407最近在看QPID 首先看下QPID是什么,他是个消息队列,用 ... -
短网址的原理和实现
2013-01-22 15:36 15306微博上经常会看到类似 http://t.cn/Afafhe 这 ... -
Tomcat7.0下实现的websocket 代码
2013-01-07 19:37 938测试环境: JDK1.6 Tomcat7.0.30 ... -
java IO写入文件效率——几种方法比较
2012-11-02 11:17 1052总结: 如果按字符和字节来分类,除方法1和2,其余都是按字符 ... -
Apache自带压力测试工具AB的使用方法
2012-09-18 11:26 1275使用例子: 1、打开dos界面,开始-》运行-》输入“cmd ... -
MyEclipse6.01注册码,Java源码
2012-07-02 16:12 1069不用为注册码犯愁了.. 下面是在网上搜索到的一段代码 ,分享给 ... -
ant解决OutOfMemoryError 或者Error starting modern compiler
2012-05-11 16:36 1342起因:在执行ant脚本的时候 ,报的错误是 Error st ... -
Java中使用Json 用到的jar包
2012-02-22 08:25 1341操作json开源的Jar包很多 ,那么多的jar选择哪个好呢 ... -
JsonUtils 类,将任意数据格式转换为Json格式
2012-02-21 09:12 1782package json; ... -
Java生成二维码或一维条形码(待续 未完)
2012-02-13 08:22 1721Java生成二维码或一维条形码(待续) 前段时间用了“ ... -
Java操作SVN(待续)
2012-02-02 08:31 982一般大家都会直接使用snv客户端或者在eclipse中svn插 ... -
使用BeanUtils类简化request和resultset转换
2012-02-01 15:41 1058转:http://xdwangiflytek.iteye.co ... -
HttpClient 网络抓取
2012-01-20 10:08 1096利用 HttpClient 进行抓取 ... -
用Java实现按字节长度截取中英文数字字符串的方法总结 .
2011-12-20 16:59 1618转:http://blog.csdn.net/yanwudin ... -
JAVA读写INI文件,亲测
2011-12-01 16:01 4022代码如下: import java.io.Buf ...
相关推荐
java中堆(heap)和堆栈(stack)有什么区别
栈(stack)与堆(heap)都是Java用来在Ram中存放数据的地方。与C++不同,Java自动管理栈和堆,程序员不能直接地设置栈或堆。
栈(stack)与堆(heap)都是Java用来在Ram中存放数据的地方。与C++不同,Java自动管理栈和堆,程序员不能直接地设置栈或堆。
第二,Java 虚拟机栈(Java Virtual Machine Stack),早期也叫 Java 栈 第三,堆(Heap),它是 Java 内存管理的核心区
什么是线程和进程? **进程与线程的区别? 什么是TreeMap 如何停止一个正在运行的线程?... 解释内存中的栈(stack)、堆(heap)和方法区(method area)的用法。 多线程同步有哪几种方法? 什么是自旋?
Java2023年最新高级面试题及答案,企业真面试题.md 免费下载,不需要积分 **进程与线程的区别? 什么是TreeMap ... 解释内存中的栈(stack)、堆(heap)和方法区(method area)的用法。 多线程同步有哪几种方法?
堆栈(stack),堆(heap) Java堆栈 jvm为每个新创建的线程都分配一个堆栈。堆栈以帧为单位保存线程的状态。jvm对堆栈只进行两种操作:以帧为单位的压栈和出栈操作。
一、Java基础知识 1.Java有那些基本数据类型,String是不是基本数据类型,他们有何区别。 答案: 8种基本类型 char byte short int ...而其他类型(object)的引用存储在栈(stack)中,他所指的对象存储在堆(heap)中。
2.5.4 堆(heap)和栈(stack) 20 JAVA垃圾收集器 21 3.1 垃圾收集简史 21 3.2 常见的垃圾收集策略 21 3.2.1 Reference Counting(引用计数) 22 3.2.2 跟踪收集器 22 3.3 JVM的垃圾收集策略 27 3.3.1 Serial Collector ...
堆和栈是两个不同的概念 堆和栈的区别 一、预备知识—程序的内存分配 一个由c/C++编译的程序占用的内存分为以下几个部分 1、栈区(stack)— 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等。其...
-Xss<size> 设置java线程栈存储(stack)大小。 -Xprof 输出CPU概况数据 -Xrunhprof[:help]|[:<option>=, ...] 执行 Java Virtual Machine Profiler Interface(Java虚拟机探查接口)的堆,CPU,或者...
3、解释内存中的栈(stack)、堆(heap)和静态区(static area)的用法 4、Perm Space中保存什么数据?会引起OutOfMemory吗? 5、什么是类的加载 6、如何⾃定义⼀个类加载器?你使⽤过哪些或者你在什么场景下需要⼀个⾃...
1、内存中的堆(stack)与栈(heap) 2、Java中数据在内存中的存储 基本数据类型的存储 对象的内存模型 包装类数据的存储 String类型数据的存储 数组的内存分配 内存空间的释放 3、Java内存分配中的栈 Java...
1.尽量使用final修饰符。 带有final修饰符的类是不可派生... 调用方法时传递的参数以及在调用中创建的临时变量都保存在栈(Stack)中,速度较快。其他变量,如静态变量,实例变量等,都在堆(Heap)中创建,速度较慢。
主要介绍Runtime Data Area,包括Java Stack,Native Method Stack, Program Counter Register,Method Area以及Heap 还简要介绍了Runtime Data Area周边的模块,包括Class Loader,Execution Engine,Native ...
**进程与线程的区别? 什么是TreeMap 如何停止一个正在运行的线程? Java 中,编写多线程程序的时候你会遵循哪些最佳... 解释内存中的栈(stack)、堆(heap)和方法区(method area)的用法。 多线程同步有哪几种方法?
什么是线程和进程? **进程与线程的区别? 什么是TreeMap 如何停止一个正在运行的线程?... 解释内存中的栈(stack)、堆(heap)和方法区(method area)的用法。 多线程同步有哪几种方法? 什么是自旋
18、heap和stack有什么区别。 栈是一种线形集合,其添加和删除元素的操作应在同一段完成。栈按照后进先出的方式进行处理。 堆是栈的一个组成元素 19、forward 和redirect的区别 forward是服务器请求资源,服务器直接...
简答题 22 1.面向对象的特征有哪些方面 22 ...21. 解释内存中的栈(stack)、堆(heap)和静态区(static area)的用法。 29 22.swtich 是否能作用在byte 上,是否能作用在long 上,是否能作用在String上? 31
9、解释内存中的栈(stack)、堆(heap)和静态区(static area)的用法。 10、Math.round(11.5) 等于多少?Math.round(-11.5)等于多少? 11、switch 是否能作用在byte 上,是否能作用在long 上,是否能作用在String上? ...