📄 collectiontest.java
字号:
/** * <p>Title: Collection演示程序</p> * <p>Copyright: Copyright (c) 2005</p> * * <p>Company: 刘艺</p> * * @author 刘艺 * @version 1.0 */package jbookch5.container;import java.util.*;//CollectionTest类public class CollectionTest { public CollectionTest() { Student ZhangSan=new Student("张三",90); c1.add(ZhangSan); c1.add("张三"); c1.add("李四"); c1.add(new Student("王武",85)); c1.add(new Student("赵榴",76)); c1.add(ZhangSan); printCollection(c1); c1.remove(ZhangSan); c1.remove("张三"); printCollection(c1); c2.add(ZhangSan); c2.add("李四"); printCollection(c2); c2.addAll(c1); printCollection(c2); } public static void main(String[] args){ new CollectionTest(); } private void printCollection(Collection c) { System.out.println("---------------------"); Iterator it=c.iterator(); while (it.hasNext()){ System.out.println(it.next()); } } //Collection支持多种容器类的实现 Collection c1=new ArrayList(); Collection c2=new HashSet(); }//Student类class Student { public Student(String n,int s) { name=n; score=s; } public String toString(){ String s=name+" 成绩:"+score; return s; } String name; int score;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -