package test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Vector;public class MyList implements Comparable<MyList>{
public static void main(String[] args) {
List<Integer> s = new ArrayList<>();
for (int i = 0; i < 10; i++) {
s.add(i);// 增加一个数据
}
s.remove(5);// 删除数据
s.set(1, 10);// 修改数据
for (int i = 0; i < s.size(); i++) {
System.out.print(s.get(i) + ",");// s.get(i)取得数组中的第个值
}
System.out.println();
System.out.println("*************************************");
List<Integer> s1 = new LinkedList<>();
for (int i = 0; i < 10; i++) {
s1.add(i);// 增加一个数据
}
s1.remove(5);// 删除数据
s1.set(1, 10);// 修改数据
Iterator<Integer> l = s1.iterator();
while (l.hasNext()) {
Integer l3 = l.next();
System.out.print(l3 + ",");
}
System.out.println();
System.out.println("*************************************");
List<Integer> s2 = new Vector<>();
for (int i = 0; i < 10; i++) {
s2.add(i);// 增加一个数据
}
s2.remove(5);// 删除数据
s2.set(1, 10);// 修改数据ListIterator<Integer> l1 = s2.listIterator(6);
while (l1.hasPrevious()) {
Integer l2 = l1.previous();
System.out.print(l2 + ",");Collections.sort(s); //集合排序
// Arrays.sort(s);-------数组排序
}@Override//排序方法
public int compareTo(MyList o) {
return 0;
}
}
Set
package test;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;public class MySet {
public static void main(String[] args) {
Set<Integer> s= new HashSet<>();
for (int i = 0; i < 10; i++) {
s.add(i); //增加
}
s.remove(0);//删除
for (Integer integer : s) {
System.out.print(integer+",");//打印
}
s.remove(1);//修改先删后加
s.add(1);
System.out.println();
System.out.println("*****************");
Set<Integer> s1=new TreeSet<>();
for (int i = 0; i < 10; i++) {
s1.add(i); //增加
}
s1.remove(0);//删除
Iterator<Integer> s2 = s1.iterator();
while (s2.hasNext()) {
Integer integer = (Integer) s2.next();
System.out.print(integer+",");
}
s1.remove(1);//修改先删后加
s1.add(1);
}
}