- 浏览: 114627 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
HuoYun:
兄弟,这个代码对于其他excel转换会出问题,如数据库导出的e ...
excel文件转换为pdf文件的问题总结 -
listen-raining:
这两天正在弄这个东东
excel文件转换为pdf文件的问题总结 -
李001:
你是英雄!
excel文件转换为pdf文件的问题总结 -
237304457:
少文,功 能有全事例不,
excel文件转换为pdf文件的问题总结 -
237304457:
提供大资源是哪种方式呀?
excel文件转换为pdf文件的问题总结
这个类实现了java List接口,底层完全由链表来实现。(非常好的单链表的例子)
package datasturct; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; /** * 我自己实现List 接口的MyLinkList类 * @author newapps * 2009-12-9 */ public class MyLinkList<T>{ /** * 节点内部类 * @author newapps * @param <T> 表示泛型 */ private class Node<T>{ T value; Node<T> next; Node(T value){ this.value=value; this.next=null; } } /**定义链表的头结点*/ private Node<T> head=null; /** * 链表中节点数 */ public int size() { Node<T> p; int size=0; for(p=head;p!=null;p=p.next){ size++; } return size; } /** * 判断该链表的节点数是否为零 */ public boolean isEmpty() { if(size()==0){ return true; } return false; } /** * 查找链表中是否含有某个指定节点值的节点 * @param o 节点值 * @return 是否含有 */ public boolean contains(T o) { if(isEmpty()){ return false; } Node<T> p; for(p=head;p!=null;p=p.next){ if(p.value.equals(o)){ return true; } } return false; } /** * 迭代器方法 * @return */ public Iterator iterator() { return new Itor(); } /** * 迭代器的实现类 * @author newapps * 2009-12-9 */ private class Itor implements Iterator{ /**位置*/ private int index=0; // private int cursor=0; public boolean hasNext() { if(index<size()){ return true; } return false; } public T next(){ T o = get(index++); return o; } public void remove() { MyLinkList.this.remove(size()-1); } } /** * 将集合中所有元素作为一个Object[]数组返回 * @return */ public Object[] toArray() { if(isEmpty()){ return null; } int length=size(),i=0; Object[] a=new Object[length]; Node<T> p; for(p=head;p!=null;p=p.next){ a[i]=p.value; i++; } return a; } /** * 由于list接口是有序 * 所以链表中添加节点数 * 应当在最后一个节点位置后添加 * @param o 节点值 * @return 添加是否成功 */ public void add(T o){ if(isEmpty()){ head=new Node<T>(o); }else{ Node<T> p=head; Node<T> node=new Node<T>(o); while(p.next!=null){ p=p.next; } p.next=node; node.next=null; } } /** * 要删除链表中某个节点的值 * 首先要找到该节点 * 最后才删除 * @param o * @return */ public boolean remove(T o){ Node<T> p=head,p1=null; boolean have=false; if(isEmpty()){ return false; } while(p!=null){ if(p.value.equals(o)){ if(p1==null){ head=head.next; }else{ p1.next=p.next; } have=true; } p1=p; p=p.next; } return have; } /** * 查找集合中所有元素在该链表中是否也存在 * @param c * @return */ public boolean containsAll(Collection c) { if(isEmpty()){ return false; } if(c.size()==0){ return false; } if(c==null||c.size()>size()){ return false; } Iterator it=c.iterator(); while(it.hasNext()){ T o=(T)it.next(); if(!contains(o)){ return false; } } return true; } /** * 将集合所有的元素添加到链表中 * @param c * @return */ public boolean addAll(Collection c){ if(c==null||c.size()==0){ return false; } Iterator it=c.iterator(); while(it.hasNext()){ T o=(T)it.next(); add(o); } return true; } /** * 从指定的下标位置将集合中所有的元素添加到链表中 * @param index * @param c * @return */ public boolean addAll(int index, Collection c) { if(c==null||c.size()==0){ return false; } if(isEmpty()){ addAll(c); return true; } if(index<-1){ return true; }else if(index>=size()){ addAll(c); }else{ int i=index; Iterator it=c.iterator(); while(it.hasNext()){ T o=(T)it.next(); add(i,o); i++; } } // 将集合中 return false; } /** * 在链表中删除包含集合中的所有元素 * @param c * @return */ public boolean removeAll(Collection c){ if(c==null||c.size()==0){ return false; } if(isEmpty()){ return false; } Node<T> p; Iterator it=c.iterator(); while(it.hasNext()){ T o=(T)it.next(); remove(o); } return true; } /** * 在链表中仅保留集合中的元素其余的全部删除 * @param c * @return */ public boolean retainAll(Collection c) { if(isEmpty()){ return false; } if(c==null||c.size()==0){ return false; } Node<T> p; for(p=head;p!=null;p=p.next){ T m=p.value; boolean have=false; Iterator it=c.iterator(); while(it.hasNext()){ T o=(T)it.next(); if(m.equals(o)){ have=true; } } if(!have){ this.remove(m); } } return true; } public void clear() { head=null; } /** * 依据指定的下标,找出链表中的元素的值 * @param index * @return */ public T get(int index) { int i=-1; if(isEmpty()){ return null; } if(index<0||index>size()){ return null; } Node<T> p=head; while(p!=null){ i++; if(i==index){ return p.value; } p=p.next; } return null; } /** * 替换链表指定位置的元素 * 并返回替换前的元素 * @param index * @param element * @return */ public T set(int index, T element) { int i=-1; if(isEmpty()){ add(element); return null; } if(index<0||index>size()){ return null; } Node<T> p=head; T o=null; while(p!=null){ i++; if(i==index){ o=p.value; p.value=element; return o; } p=p.next; } return null; } /** * 在链表的指定位置添加一个元素 * @param index * @param element */ public void add(int index, T element) { int i=-1; if(isEmpty()){ this.add(element); return; } if(index<0||index>size()){ return; } Node<T> p=head,p1=null; while(p!=null){ i++; if(i==index){ Node<T> newNode=new Node<T>(element); if(p1==null){ newNode.next=head; head=newNode; }else{ p1.next=newNode; newNode.next=p; } } p1=p; p=p.next; } } /** * 在链表中删除指定位置的元素 * @param index * @return */ public T remove(int index) { if(isEmpty()){ return null; } if(index<0||index>size()){ return null; } Node<T> p=head,p1=null; int i=-1; while(p!=null){ i++; if(i==index){ if(p1==null){ head=head.next; }else{ p1.next=p.next; } return p.value; } p1=p; p=p.next; } return null; } /** * 在链表中返回包含指定元素的下标,如果没有找到则返回-1; * @param o * @return */ public int indexOf(T o) { int i=-1; if(isEmpty()){ return -1; } Node<T> p=head; while(p!=null){ i++; if(p.value.equals(o)){ return i; } p=p.next; } return -1; } /** * 在链表中找出指定元素最后一次出现的下标 * 如果没有找到则返回-1; * @param o * @return */ public int lastIndexOf(T o) { if(isEmpty()){ return -1; } Node<T> p=head; int i=-1,index=-1; while(p!=null){ i++; if(p.value.equals(o)){ index=i; } p=p.next; } return index; } /** * 链表的打印方法 * */ public void printLinkList(){ Node<T> p; for(p=head;p!=null;p=p.next){ System.out.print(p.value+"--->"); } System.out.println(); } public static void main(String args[]){ MyLinkList<String> list=new MyLinkList<String>(); //System.out.println(list.isEmpty()); int [] s=new int[5]; list.add("5"); list.add("6"); list.add("7"); list.add("8"); Collection c=new ArrayList(); c.add("9"); c.add("10"); c.add("11"); c.add("8"); //list.remove("8"); //list.add(0,"50"); //list.remove(2); //System.out.println(list.set(2,"100")); //System.out.println(list.get(2)); //list.addAll(c); //list.printLinkList(); //list.retainAll(c); list.addAll(2,c); list.printLinkList(); Iterator it=list.iterator(); while(it.hasNext()){ System.out.print(it.next()+"---"); } // it.remove(); // it.remove(); // it.remove(); // it.remove(); list.clear(); list.printLinkList(); //System.out.println(list.indexOf("9")); //System.out.println(list.lastIndexOf("8")); //System.out.println(list.contains("10")); } }
发表评论
-
java 解析数学表达式
2011-11-20 10:33 5534数学表达式解析工具类: 支持负数运算, 多层括号嵌套运算 ... -
java代码模拟计算机实现原理(一)加法器模拟
2011-09-29 23:30 3262加法器是有两种基本逻辑门电路:异或门、与门电路组成的 ... -
jar 命令简介
2011-02-16 09:55 1180jar 命令用途:采用zip和ZLIB的压缩格式,将一系列程序 ... -
javac 命令
2011-02-16 09:17 1310最简单的方式(javac -d)首先,需要编译JAVA文件,需 ... -
阿拉伯数组转换成对应中文
2011-02-12 11:52 1119package com.heda.code; publi ... -
java二叉树实现
2011-02-12 11:50 1036package com.heda.code; publi ... -
最大公约数和最小公倍数
2011-02-12 11:48 998package com.heda.code; publi ... -
比较完整数据源实现
2010-06-12 21:35 1438package com.bpsoft.bl ... -
jxl 操作excel Demo
2010-05-25 16:02 1314程序是用:jxl技术来操作excel文档的,实现了excel插 ... -
Jacob操作Word详细教程
2010-05-11 21:16 5399首先, ... -
Java 正则表达式小结
2010-05-11 20:25 1468Java 中正则表达式是在Java 1.4版本以后才出现的。在 ... -
DOM写的xml工具类
2010-04-05 16:15 1370package xml_util; import j ... -
日志记录器
2010-03-12 23:12 960package log_util; import jav ... -
java1.5新特性枚举实现原理
2010-03-09 00:24 1121package com.bp_soft.day01; /** ... -
Struts 1实现原理之我理解
2010-03-06 23:23 1466Struts是在servlet基础上设计的一种框架。下面看一段 ... -
JDBC模板类实现(version1.1)
2010-01-30 14:34 1346package daoUtil.daoTemplate; ... -
BeanUtils.copyProperties(son, father)使用感想
2010-01-28 12:20 3156BeanUtils.copyProperties(son, f ... -
jdbc数据源
2010-01-20 19:06 1053数据源设计思想和数据库连接池设计思想基本相似。大家知道在操作数 ... -
经典JDBC DAOFactory类实现
2010-01-09 23:02 2408package ajax.user.language.fact ... -
WEB应用中常用的数据库连接池
2009-12-26 16:07 1349数据库连接池是WEB应用中必不可少的东西,这是我个人最近参照别 ...
相关推荐
java中LinkedList集合类实现栈和队列.docjava中LinkedList集合类实现栈和队列.docjava中LinkedList集合类实现栈和队列.docjava中LinkedList集合类实现栈和队列.docjava中LinkedList集合类实现栈和队列.doc
模拟实现 LinkedList 测试类
链表类LinkedList的完全c++实现,根据数据结构与算法课堂总结。
数据结构,LinkedList在c++的实现,一共有三个头文件:Link.h 、List.h 、LinkedList。
7.2.2 LinkedList实现类;7.2.2 LinkedList实现类;7.2.2 LinkedList实现类;7.2.2 LinkedList实现类;7.2.2 LinkedList实现类;7.2.2 LinkedList实现类;7.2.3 学生实践练习(一);7.2.3 学生实践练习(一);7.2.3 学生...
javascript 集合类 LinkedList代码实现
栈是先进先出的原则,该类实现了栈的移入移除
该资源利用基础的链表结构,结合泛型和反射的知识点,实现重写LinkedList集合类,可以存放任意类型数据。比较推荐对Java有稳固基础的同学来阅读,为了方便阅读,代码的注释写的非常的清楚
复习内容
使用LinkedList类编写程序,用某种集合接口的实现类作存储,实现具有自定义排序功能的包含姓名、年龄、身高、职称等内容的人事信息输入和打印。
1.List是接口类,ArrayList和LinkedList是List的实现类 2.ArrayList是动态数组(顺序表)的数据结构 3.LinkedList
List<String> l1=new LinkedList();//使用泛型 //List l1= new LinkedList(); int index=0; //插入元素 l1.add("firstElement"); l1.add("secondElement"); l1.add("thirdElement"); //访问索引 ...
下面小编就为大家带来一篇java 集合之实现类ArrayList和LinkedList的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
java代码-定义一个学生类,使用LinkedList对学生类进行管理 软件9班 48 李昌文
本文实例讲述了C#双向链表LinkedList排序实现方法。分享给大家供大家参考。具体如下: 1.函数 打印链表函数PrintLinkedList 和 排序函数SortLinkedList 注:下面代码中的链表每项都是double类型,如果换做其他的类型...
1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构。 2.对于随机访问get和set,ArrayList觉得优于LinkedList,因为LinkedList要移动指针。 3.对于新增和删除操作add和remove,...
LinkedList与ArrayList都是List接口的具体实现类。下面将介绍如何实现一个简单的LinkedList,具有很好的参考价值,下面跟着小编一起来看下吧
java代码-【3】定义一个学生类,使用LinkedList对学生类进行管理,执行添加操作,并打印数据。 运行效果图为: 任务: 1.定义一个学生类Student (1)属性为:学号stuId(int),姓名name(String),成绩...
java代码-定义一个学生类,使用LinkedList对学生类进行管理,执行添加操作,并打印数据。