public class dome {
public void setDemo() {
Set set = new HashSet();//这个是无序的
Set set = new TreeSet();//这个是有序的
String s1=new String("hello");
String s2 = s1+s1;
String s3 = new String("world");
//添加
set.add(s1);
set.add(s2);
set.add(s3);
System.out.println(set.size());
boolean isExists =false;
Iterator iterator=set.iterator();
while (iterator.hasNext()) {
String oldStr=(String) iterator.next();
System.out.println(oldStr);
/*
if(s3.equals(oldStr)) {
isExists=true;
System.out.println("SDD");
}*/
}
}
public void listDemo() {
List list =new ArrayList();
list.add("ddd");
list.add("sss");
for(int i=0;i<list.size();i++) {
System.out.println(list.get(i));
}
Iterator it =list.iterator();
while(it.hasNext()) {
boolean bl=false ;
list.contains("sss");
System.out.println(it.next());
}
}
public void mapDemo() {
Map map = new HashMap();
map.put("a", "1");
map.put("b", "2");
map.put("c", "3");
map.put("d", "4");
System.out.println(map.get("a"));
System.out.println(map.get("b"));
System.out.println(map.get("c"));
System.out.println(map.get("d"));
}
public static void main(String[] args) {
dome s=new dome();
s.mapDemo();
}
}
网友评论