set以及map集合

一、map集合

public void text1(){
//map集合
Map<String,Integer>map1=new HashMap<String,Integer>();
//取值
map1.put("height",123);
map1.put("age",123);
//使用泛型进行赋值
Set<Entry<String,Integer>>entrySet=map1.entrySet();
//for打印输入
for(Entry<String,Integer> aaa : entrySet){
System.out.println(aaa.getKey()+"======"+aaa.getValue());
}
}

二、set集合

//使用set取消重复代码
public void text2(){
Set<String> set2 =new HashSet<String>();
set2.add("1");
set2.add("2");
set2.add("2");
//输入结果:1,2 2有两个重复的,所以只要一个
System.out.println(set2);
}

在main调用text();

public static void main(String[] args) {

//tex5是文件名类,text_05是赋值!

//点出来当前类名!

text5 text_05=new text5();
text_05.text1();
}

原文地址:https://www.cnblogs.com/wsx123/p/13734824.html