import jdk.swing.interop.SwingInterOpUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
public class HashMapDemo {
public static void main(String[] args) {
String [] str={"中文","计算机","ABC","123","qq@qq.com"};
//1 Arrays.asList(str);将数组装换成列表
List<String> list =Arrays.asList(str);
System.out.println(list);
//2 把数组转换成arraylist new Arraylist<>(Arrays.aslist(str))
ArrayList<String> alist =new ArrayList<>(Arrays.asList(str));
alist.add("haha");
System.out.println(alist);
alist.remove("ABC");
System.out.println(alist);
//3 把数组转换成 LinkedList new LinkedList<>(Arrays.asList(str))
LinkedList<String> llist =new LinkedList<>(Arrays.asList(str));
llist.add("haha");
System.out.println(llist);
llist.remove("ABC");
System.out.println(llist);
//4 将列表转换成数组组 toArray()
Object[]temp =llist.toArray();
for (Object O:temp){
System.out.println(O+"\t");
}
}
}
import jdk.swing.interop.SwingInterOpUtils;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Hashtable;
public class Sb1 {
public static void main(String[] args) {
String [] str={"中文","计算机","ABC","123","qq@qq.com"};
//1 将数组转换成集合 set
HashSet<String> set =new HashSet<>((Arrays.asList(str)));
System.out.println(set);
//2 将set转换成数组
Object[]temp =set.toArray();
for (int i = 0 ; i < temp.length ; i++ ){
System.out.println(temp[i] + "\t ");
}
}
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
public class Sb2 {
public static void main(String[] args) {
HashMap<String,String>map =new HashMap<>();
map.put("1","haha");
map.put("2","ha1ha");
map.put("3","he");
map.put("4","ha");
//将map中的键取出一个集合
System.out.println(map.keySet());
//将map中的键取出一个列表
ArrayList<String> list =new ArrayList<>(map.keySet());
System.out.println(list);
//将map中的值转换成一个集合
System.out.println(map.values());
//将map中的值转换成一个列表
LinkedList<String> list2 =new LinkedList<>(map.values());
System.out.println(list2);
}
}
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class Sb3 {
public static void main(String[] args) {
HashMap<String,String>map =new HashMap<>();
map.put("1","aaa");
for (int i=0;i<100000;i++){
map.put(String.valueOf(i),"aaa"+i);
}
//迭代器
Iterator<Map.Entry<String,String>>iterator=map.entrySet().iterator();
while (iterator.hasNext()){
Map.Entry<String,String>next=iterator.next();
System.out.println(next);
}
}
}