The List interface inherits from the Collection interface... the element sequence is inserted in the order of... there are 2 lists.
ArrayList and sorted list are variable-length arrays, but they are stored in different ways .. ArrayList is stored in arrays and is suitable for searching elements ,,
The sort list is a linked list storage structure suitable for efficient insertion and deletion.
Both the listlist and ArrayList implement the List interface.
The Iterable interface can be used to iterate for loop operations... Elements cannot be deleted through the set of iterations for loop...
When using list, we often need to return a sublist of List.
We know that there is a subList method in the List interface that can return the index length from 0 to List
A subview of the element. This view maps to the original list. adding or deleting a subview will affect the original list;
Looking at the following code, we found that we first deleted all elements in the view to delete all the Child list elements in the list. The result is null.
We have added elements to the original list through the sublist view. We can see that the elements are added to the right of the original list...
Import java. util. ArrayList;
Import java. util. List;
Class MyObject {
Static int I = 0;
@ Override
Public String toString (){
// TODO Auto-generated method stub
Return this. getClass (). getName ();
}
}
Public class MyArray {
Private List <MyObject> l = new ArrayList <MyObject> ();
Public void add (MyObject... obj ){
For (MyObject tem: obj ){
L. add (tem );
}
}
Public void show (){
System. out. println (this. l );
}
Public static void main (String [] args ){
MyArray arr = new MyArray ();
MyObject ss [] = {new MyObject (), new MyObject ()};
Arr. add (ss );
System. out. println ("Raw data ");
Arr. show ();
List <MyObject> ll = arr. getSub (); // returns a List Of all values between 0 and 4 excluding index 4.
System. out. println ("deleting all elements from the subview ");
Ll. removeAll (ll); // delete all lists from the sublist
Arr. show ();
System. out. println ("add through subview ");
Ll. add (MyObject) new MyObject ());
Ll. add (MyObject) new MyObject ());
Ll. add (MyObject) new MyObject ());
Arr. show ();
}
Public List <MyObject> getSub (int I, int j ){
Return l. subList (I, j );
}
}
Author: yue7603835