1 Packagecn.arraylist.com;2 3 Importjava.util.ArrayList;4 ImportJava.util.Iterator;5 6 Public classArrayListDemo2 {7 8 Public Static voidMain (string[] args) {9 //TODO auto-generated Method StubTenArrayList ArrayList =NewArrayList (); OneArraylist.add ("Li"); AArraylist.add ("Liu"); -Arraylist.add ("Huang"); -Arraylist.add ("Li"); theArraylist.add ("Huang"); - - //sort of method to repeat - for(intx = 0; x < Arraylist.size ()-1; X + +) {//when the index value x=0, in turn and in the inner loop to compare, when X=0 + for(inty = x + 1; Y < arraylist.size (); y++) {//y=x+1, each X-contrast starts at the back of the index - if(Arraylist.get (x). Equals (Arraylist.get (y))) {//get the values of x and Y to compare + arraylist.remove (y); A } at } - } - //iterators -Iterator it =arraylist.iterator (); -string[] ss = {}; - while(It.hasnext ()) { inString s =(String) It.next (); - System.out.println (s); to + } - the } * $}
Set to repeat the introduction of sorting ideas