import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class AA {
public static void main(String[] args) throws IOException {
//copy(List m,List n)方法的使用:
//(含义:将集合n中的元素全部复制到m中,并且覆盖相应索引的元素)。
List mList = Arrays.asList("one two three four five six siven".split(" "));
System.out.println(mList);
List nList = Arrays.asList("我 是 复制的".split(" "));
System.out.println(nList);
Collections.copy(mList, nList);
System.out.println(mList);
}
}
2.sort(list)方法的使用(含义:对集合进行排序)。
public static void main(String[] args) throws IOException {
List mList = Arrays.asList("j a v a e e ".split(" "));
Collections.sort(mList);
System.out.println(mList);
}
3.shuffle(Collection)方法的使用(含义:对集合进行随机排序)。
public static void main(String[] args) throws IOException {
List mList = Arrays.asList("j a v a e e ".split(" "));
Collections.shuffle(mList);
System.out.println(mList);
Collections.shuffle(mList);
System.out.println(mList);
}
4.reverse()方法的使用(含义:反转集合中元素的顺序)。
public static void main(String[] args) throws IOException {
List mList = Arrays.asList("j a v a e e ".split(" "));
System.out.println(mList);
Collections.reverse(mList);
System.out.println(mList);
}
5.binarySearch(Collection,Object)方法的使用(含义:查找指定集合中的元素,返回所查找元素的索引)
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class AA{
public static void main(String[] args) throws IOException {
//binarySearch(Collection,Object)方法的使用(含义:查找指定集合中的元素,返回所查找元素的索引)
List mList = Arrays.asList("j a v a e e k".split(" "));
System.out.println(mList);
int m = Collections.binarySearch(mList, "a");
System.out.println(m);
int n = Collections.binarySearch(mList, "e");
System.out.println(n);
int t = Collections.binarySearch(mList, "k");
System.out.println(t);
List c = new ArrayList();
c.add("j");
c.add("a");
c.add("v");
c.add("a");
c.add("e");
c.add("e");
c.add("k");
System.out.println(c);
int m1 = Collections.binarySearch(c, "a");
System.out.println(m1);
int n1 = Collections.binarySearch(c, "e");
System.out.println(n1);
int t1 = Collections.binarySearch(c, "k");
System.out.println(t1);
}
}



