MAP的 遍历

JDK1.4中 Map map = new HashMap();Iterator it = map.entrySet().iterator();while (it.hasNext()) {Map.Entry entry = (Map.Entry) it.next();Object key = entry.getKey();Object value = entry.getValue();} JDK1.5中,应用新特性For-Each循环 Map m = new HashMap();for(Object o : map.keySet()){ map.get(o);} 返回的 s...
2010-06-07 10:59 | 阅读 997 次 | 评论 1 条

java数据结构(集合)java数据结构内容整理

关键字: 数据结构 Collection:List、Set Map:HashMap、HashTable 如何在它们之间选择 一、Array , Arrays Java所有“存储及随机访问一连串对象”的做法,array是最有效率的一种。 1、 效率高,但容量固定且无法动态改变。 array还有一个缺点是,无法判断其中实际存有多少元素,length只是告诉我们array的容量。 2、Java中有一个Arrays类,专门用来操作array。 arrays中拥有一组static函数, equals():比较两个array是否相等。array拥有相同元素个数,且所有对应元素两两相等。...
2010-05-23 00:16 | 阅读 1430 次 | 评论 0 条

ArrayList和LinkedList的用法区别

关键字: jdk 1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构。 2.对于随机访问get和set,ArrayList觉得优于LinkedList,因为LinkedList要移动指针。 3.对于新增和删除操作add和remove,LinedList比较占优势,因为ArrayList要移动数据。 这一点要看实际情况的。若只对单条数据插入或删除,ArrayList的速度反而优于LinkedList。但若是批量随机的插入删除数据,LinkedList的速度大大优于ArrayList. 因为ArrayList每插入一条数据,要移动插...
2010-05-22 23:52 | 阅读 1388 次 | 评论 0 条

TempFile临时文件的创建

import java.io.*;import java.awt.event.*;import javax.swing.*; public class TestTempFile implements ActionListener{ private File tempPath; public static void main(String args[]){ TestTempFile ttf = new TestTempFile(); ttf.init(); ttf.createUI(); } public void createUI(){ JFrame frame = new ...
2010-05-21 16:01 | 阅读 869 次 | 评论 0 条

集合综合理论编

讲述的是集合一章中的内容Set:不区分元素的顺序,不允许出现重复的值list:区分元素的顺序,且允许出现重复的值map:采用key——values的,不允许有重复的键,每个键最多对应一个值java集合只能保存引用类型的数据,是对象的引用Collection接口描述set和list集合类型的根接口相关方法: add()如果增加重复元素,则增加失败,返回false contains()判断是否包含有某个元素 iterator()返回成一个迭代器List可以对元素的插入位置进...
2010-05-21 11:08 | 阅读 852 次 | 评论 0 条

Arrays的实例

import java.util.List;import java.util.Arrays;public class TestArrays{ public static void main(String[] args) { Integer[] a = {3,25,12,79,48}; System.out.println(a); System.out.println(Arrays.toString(a)); Arrays.sort(a); System.out.println(Arrays.toString(...
2010-05-21 11:07 | 阅读 766 次 | 评论 0 条

shuffle数字混排

import java.util.ArrayList;import java.util.Collections;public class Game{ ArrayList cards; public static void main(String[] args) { Game g = new Game(); g.deal(); g.display(); } public ArrayList deal(){ if(cards == null){ cards = new Array...
2010-05-21 11:00 | 阅读 981 次 | 评论 0 条

TestCollections实例

import java.util.Vector;import java.util.ArrayList;import java.util.Collections;import java.util.Enumeration;public class TestCollections{ public static void main(String[] args) { ArrayList alist = new ArrayList(); alist.add(75); alist.add(38); alist.add(21); ...
2010-05-21 10:56 | 阅读 843 次 | 评论 0 条

HashMap的应用

import java.util.Set;import java.util.HashMap;import java.util.Collection;import java.util.Iterator;public class TestHashMap{ public static void main(String[] args) { HashMap hm = new HashMap(); hm.put(new Integer(1003),new Person(1003,"张三",15)); hm.put(new Integer(1008)...
2010-05-21 10:39 | 阅读 1080 次 | 评论 0 条

Comparable实例

import java.util.TreeSet;import java.util.Iterator;public class TestComparable{ public static void main(String[] args) { TreeSet ts = new TreeSet(); ts.add(new Person(1003,"张三",15)); ts.add(new Person(1008,"李四",25)); ts.add(new Person(1015,"王五",73)); ts.add...
2010-05-21 10:27 | 阅读 1065 次 | 评论 1 条

TreeS用的相关实例

import java.util.TreeSet;import java.util.Iterator;public class TestTreeSet{ public static void main(String[] args) { TreeSet ts = new TreeSet(); ts.add("orange"); ts.add("banana"); ts.add("apple"); ts.add("grape"); Iterator it = ts.iterator(); ...
2010-05-21 10:13 | 阅读 785 次 | 评论 0 条

hashset的实例

package com.yds.review.list11;import java.util.Date;import java.util.HashSet;import java.util.Iterator;public class TestHashSet{ public static void main(String[] args) { HashSet h = new HashSet(); h.add("1st"); h.add("2nd"); h.add(new Integer(3)); h.add(new...
2010-05-21 10:05 | 阅读 945 次 | 评论 0 条

Iterator

import java.util.Date;import java.util.ArrayList;import java.util.Vector;import java.util.Iterator;public class TestIterator{ public static void main(String[] args) { ArrayList a = new ArrayList(); a.add("China"); a.add("USA"); a.add("Korea"); Iterator it...
2010-05-21 09:58 | 阅读 799 次 | 评论 0 条

stack的实例

import java.util.Date;import java.util.Stack;public class TestStack{ public static void main(String[] args) { Stack s = new Stack(); s.push("hello"); s.push(new Date()); s.push(400); //自动封装,等价于s.push(new Integer(400)); s.push(3.14); System.o...
2010-05-21 09:51 | 阅读 849 次 | 评论 0 条

vector实例

package com.yds.review.list11;import java.util.Date;import java.util.Vector;public class TestVector{ public static void main(String[] args) { Vector v = new Vector(); v.add("1st"); v.add("2nd"); v.add(new Integer(3)); v.add(new Double(4.0)); v.add("2...
2010-05-21 09:44 | 阅读 982 次 | 评论 0 条

第一个实例

package com.yds.review.list11;import java.util.Date;import java.util.ArrayList;public class TestArrayList{ public static void main(String[] args) { ArrayList h = new ArrayList(); h.add("1st"); h.add("2nd"); h.add(new Integer(3)); h.add(new Double(4.0)); ...
2010-05-21 09:42 | 阅读 861 次 | 评论 0 条
浏览274670次