ArrayList
- Use Arraylist implement storage objects will be deleted calendar and duplicate objects
public static void main(String[] args) {
ArrayList list = new ArrayList();
list.add(100);
list.add(100);
list.add(100);
list.add(100);
list.add(100);
list.add(100);
list.add(200);
deleEle(list);
System.out.println(list);
}
private static void deleEle(ArrayList list) {
for (int i = 0; i < list.size(); i++) {
Object obj = list.get(i);
if(list.indexOf(obj)!=list.lastIndexOf(obj)){
list.remove(obj);
deleEle(list);
}
}
}
Vector
-
Vector Class Overview: Vector class implements a growable array of objects, Vector is synchronized.
-
Vector class-specific features
public void the addElement (E obj)
public E elementAt (int index)
public the Enumeration Elements ()
LinkedList
-
LinkedList class overview: List linked list implementation of the interface, this implementation is not synchronized
-
LinkedList class-specific features
public void addFirst (E e) and addLast (E E)
public E getFirst () and getLast ()
public removeFirst E () and public E removeLast ()
Generics
-
Generic wildcard <?>: Any type, if not explicitly, then that Object as well as any of the Java class
-
? Extends E: downward limit, E and its subclasses
-
? Super E: limited upward, E and its parent class
ArrayList objects = new ArrayList();
//?泛型统配符
ArrayList<?> objects2 = new ArrayList();
//向上限定
ArrayList<? super Animal> objects3 = new ArrayList();
//ArrayList<? super Animal> objects4 = new ArrayList();
ArrayList<? super Animal> objects4 = new ArrayList();
//向下限定
ArrayList<? extends Animal> objects5 = new ArrayList();
ArrayList<? extends Animal> objects6= new ArrayList();
ArrayList<? extends Animal> objects7 = new ArrayList();
ArrayList list = new ArrayList<>();
list.add(20);
ArrayList list2 = new ArrayList<>();
list2.add(200);
list.addAll(list2);
-
If generic data types defined the future, then the requirements of both sides must be the same type of data
-
Variable parameters Overview: definition of the method when not know how many parameters that define the
Format: Method Name Modifier return type (data type ... variable name) {}
Note:
A: variable here is actually an array
b: if there is a variable parameter method, and there are a number of parameters, then the variable parameters must be the last one