JAVA——集合
1.单一赋初值 Array.fill(i,47);
Array.fill(j,78);
2.将一个集合中的值赋给另一个集合System.arraycopy(i,0,j,0,i.length);
3.set和Map不接受重复元素,list最重要的特性是—次序,add存,get取,集合使用时最好用泛型规范。
4.Iterator:hasNext:检查是否有其他元素, next:取得下一个元素,remove:移取迭代器最新传回的元素
5.若在HashMap中使用自定义的class作为key,得同时覆写hashcode和equals,hashCode()所产生的hash code——从key对象中得出一个数字,作为Array的索引。
6.Map KeySet ,遍历Map的方法,通过Key找Value (待补充)
7.HashMap初始化,赋值示例:
HashMap<String,Integer> hm = newHashMap<String,Integer>();
for(inti=0;i<5;i++){
hm.put("A"+i,i);
}
8.HashMap取值
Stringstr ="A4";
System.out.println("key="+str+"and—value="+hm.get(str));
9.遍历
for(Stringkey: h m.keySet()){
System.out.print("key="+key+"andvalue="+hm.get(key));
}
10.使用迭代器遍历
Iteratoriterator = hm.keySet().iterator();
while(iterator.hasNext()){
system.out.println(hm.get(iterator.next()).toString());