版本1.2才有了集合的概念
1.代码书写步骤:
1.1声明集合
1.1.1链表:ArrayList<Integer> al增删节点快。
1.1.2映射:Map<String, String> browMap
泛型——指定集合内元素类型。
自动装/拆箱——基本数据类型和包装类之间相互装换。int<==>integer
1.2为集合分配内存空间
1.2.1 al=new ArrayList<Integer>()
1.2.2 browMap=new HashMap<String,String>()
1.3为集合对象赋值
1.3.1
1.3.2 browMap.put(key, value)
1.4集合的应用与显示。
1.4.1显示集合元素的方式
1.4.1.1for循环——list(下标)
1.4.1.2for-each(1.5提出)循环for(Element e1:ListURL){System.out.println(e1);}Element是ListURL的元素类型
1.4.1.3:Iterator类——hasnext(),next()
map先转为set在用上面的方法显示。
2集合结构
2.1Linkedlist——双线链表
2.2:ArryList(1.2版;线程不安全)/Vector(1.2以前;线程安全)——线性
2.3:hashset——单向散列(效率高
2.4:treeset——平衡二叉树(可以排序 (comparator))
2.5:hashmap——1.2版;线程不安全;咏絮空键空值
2.6:hashtable——更早版本;线程安全;不允许空键空值
2.6.1:properties是hashtable的子类,存放字符串;kv对可修改;load、store方法;