Java集合学习简单demo整理
public class Demo {
public static void main(String[] args){
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
if (list.contains(2)){
System.out.println("ok");
}
Collection<Integer> days = new ArrayList<Integer>();
for (int i=0;i<10;i++){
days.add(i);
}
System.out.println(days);
Iterator iterator = days.iterator();
while (iterator.hasNext()){
System.out.println(iterator.next());
}
List<String> stringList = Arrays.asList("java","go","rust","kotlin");
Iterator iterator1 = stringList.iterator();
while (iterator1.hasNext()){
System.out.println(iterator1.next());
}
String[] arr1 = {"java","go"};
String[] arr2 = Arrays.copyOf(arr1,4);
for (String str:arr2) {
System.out.println(str);
}
Map<String,String> map = new HashMap();
map.put("aa","11");
map.put("bb","22");
System.out.println(map.keySet());
System.out.println(map.entrySet());
Set<String> set = new HashSet<String>();
set.add("aa");
set.add("bb");
System.out.println(set);
}
}