-
public void testGet(){ int size = coursesToSelect.size(); System.out,orintl("有以下课程可选"); for(int i=0;i<size,i++) Course cr = (Course)coursesT0oSelect.get(i); System.out.printl("课程:"+cr.id+"."+cr.name); } public static void main(String[] args){ ListTest lt = new ListTest(); lt.testAdd(); lt.testGet(); lt.testIterator(); } }
查看全部 -
public void testRemove(){ //Course cr = (Course)coursesToSelect.get(4); System.out.println("即将删除4位置上的课程"); coursesToSelect.remove(4); System.out.println("成功删除"); testForEach(); }
查看全部 -
public void testRemove(){ Course cr = (Course)coursesToSelect.get(4); System.out.println(cr.id+cr.name); coursesToSelect.remove(cr); System.out.println("成功删除"); testForEach(); }
查看全部 -
public static void main(String[] args){ ListTest lt = new ListTest(); lt.testAdd(); lt.testGet(); lt.testlterator(); lt.testForEach(); lt.testModify(); lt.testForEach(); lt.testRemove(); }
查看全部 -
public void testGet(){ int size = coursesToSelect.size(); for(int i=0;i<size;i++){ Course cr = (Course)cursesToSelect.get(i); System.out.println("课程:"+cr.id+":"+cr.name); } }
查看全部 -
package lmr; import java.util.List; public class ListTest{ public List coursesToSelect; public ListTest(){ this.ocursesToSelect = new ArrayList(); } public void testAdd(){ Course cr1 = new Course("1","数据结构"); courseToSelect.add(cr1); Course temp = (Course)coursesToSelect.get(0); System.out.println("添加了课程:"+temp.id+":"+temp.name); Course cr2 = new Course("2","C语言"); coursesToSelect.add(0,cr2); Course temp2 = (Course)coursesToSelect.get(0); System.out.println("添加了课程:"+temp2.id+":"+temp2.name); Course[] course = {new Course("3","离散数学"),new Course("4","汇编语言")}; coursesToSelect.addAll(Arrays.asList(course));\ Course temp3 = coursesToSelect.get(2); Course temp3 = coursesToSelect.get(3); System.out.println("添加了两门课程:"+temp3.id+":"+temp3.name+";"+temp4.id+":"+temp4.name); Course[] course2 = {new Course("5","高等数学"),new Course("6","大学英语")}; coursesToSelect.addAll(2,Arrays.asList(course2)); Course temp5 = (Course)coursesToSelect.get(2); Course temp5 = (Course)coursesToSelect.get(3); System.out.println("添加了两门课程:"+temp5.id+":"+temp5.name+";"+temp6.id+":"+temp6.name); } public static void main(String[]args){ ListTest lt = new ListTest(); lt.testAdd(); } }
查看全部 -
package lmr; import java.util.List; public class ListTest{ public List coursesToSelect; public ListTest(){ this.ocursesToSelect = new ArrayList(); } public void testAdd(){ Course cr1 = new Course("1","数据结构"); courseToSelect.add(cr1); Course temp = (Course)coursesToSelect.get(0); System.out.println("添加了课程:"+temp.id+":"+temp.name); Course cr2 = new Course("2","C语言"); coursesToSelect.add(0,cr2); Course temp2 = (Course)coursesToSelect.get(0); System.out.println("添加了课程:"+temp2.id+":"+temp2.name); Course[] course = {new Course("3","离散数学"),new Course("4","汇编语言")}; coursesToSelect.addAll(Arrays.asList(course));\ Course temp3 = coursesToSelect.get(2); Course temp3 = coursesToSelect.get(3); System.out.println("添加了两门课程:"+temp3.id+":"+temp3.name+";"+temp4.id+":"+temp4.name); } public static void main(String[]args){ ListTest lt = new ListTest(); lt.testAdd(); } }
查看全部 -
package lmr; import java.util.List; public class ListTest{ public List coursesToSelect; public ListTest(){ this.ocursesToSelect = new ArrayList(); } public void testAdd(){ Course cr1 = new Course("1","数据结构"); courseToSelect.add(cr1); Course temp = (Course)coursesToSelect.get(0); System.out.println("添加了课程:"+temp.id+":"+temp.name); Course cr2 = new Course("2","C语言"); coursesToSelect.add(0,cr2); Course temp2 = (Course)coursesToSelect.get(0); System.out.println("添加了课程:"+temp2.id+":"+temp2.name); } public static void main(String[]args){ ListTest lt = new ListTest(); lt.testAdd(); } }
查看全部 -
package lmr public class Student{ public String id; public String name; public Set course; public Student(String id,String name){ this.id = id; this.name = name; this.course = new HashSet(); } }
查看全部 -
package lmr; public class Course{ public String id; public String name; public Course(String id,String name){ this.id = id; this.name = name; } }
查看全部 -
Map接口:
Map提供了一种映射关系,其中的元素是以键值对(key-value)形式存储的,能够实现根据key快速查找value
Map中的键值对以Entry类型的对象实例形式存在
键(key值)不可重复,value值可以
查看全部 -
通过调用Collections.sort方法,添加刚刚编写的实现了Comparator接口的类作为参数,对Map进行排序。
查看全部 -
在类的定义中加上implements Comparator<泛型>,使其支持Comparator接口。
及加上compare方法
查看全部 -
另外还需要实现该接口的compareTo方法
查看全部 -
在类的定义中加上implements Comparable <泛型>,使其支持Comarable接口
查看全部
举报
0/150
提交
取消