There are two books on the desk, respectively is "journey to the west" "water margin"; There are three books on the shelf, respectively is "the romance of The Three Kingdoms", "selected poems of Shakespeare" "a dream of red mansions" use the interface of the get (int index) and set (int index, Object obj) method, will China's four great classics in accordance with the "water margin", "three kingdoms" "journey to the west" "a dream of red mansions" put together the order of the
Optimization of the time don't use a constructor thank bosses like
Package GenericProgramma;
The import com. Sun. Deploy. Config. Config.
Import the Java. Util. ArrayList;
Import the Java. Util. List;
The class ListTest
{
Public static void main (String [] args)
{
List
List1. Add (" journey to the west ");
List1. Add (" water margin ");
System. The out. Println (" there are two books on the desk are ");
For (int j=0; j
System. The out. Print (list1. Get (j) + "\ t");
}
System.out.println();
List
List2. Add (" the romance of The Three Kingdoms ");
List2. Add (" Shakespeare's poems ");
List2. Add (" a dream of red mansions ");
System. Out. Println (" shelf there are three books are ");
For (int I=0; I & lt; List2. The size (); I++)
{
System. The out. Print (list2. Get (I) + "\ t");
}
System.out.println();
System. The out. Println (" reorder: "+ list1. Get (list1. The size () - 1) +", "+ list2. Get (list2. The size () - 2) +", "+ list1. Get (list1. The size () - 2) +", "+ list2. Get (list2. The size () - 1));
}
}
CodePudding user response:
ListTableList=new ArrayList<> (a);
TableList. Add (" journey to the west ");
TableList. Add (" water margin ");
ListBookList=new ArrayList<> (a);
BookList. Add (" the romance of The Three Kingdoms ");
BookList. Add (" Shakespeare ");
BookList. Add (" a dream of red mansions ");
BookList. Add (0, tableList. Get (1));
BookList. Set (2, tableList. Get (0));
System. The out. Println (String. Join (", ", bookList));
CodePudding user response:
Don't know what is the meaning of this, if is the actual development, have the type in the table to distinguish what kind of books and number of what,CodePudding user response: