import java.util.Collections ;
import java.util.List ;
import java.util.Set ;
public class CollectionsDemo01{
public static void main(String args[]){
List<String> allList = Collections.emptyList() ; // 返回空的 List集合
Set<String> allSet = Collections.emptySet() ; // 返回空的 List集合
allList.add("Hello") ; // 加入数据
}
};
import java.util.Collections ;
import java.util.List ;
import java.util.ArrayList ;
import java.util.Iterator ;
public class CollectionsDemo02{
public static void main(String args[]){
List<String> all = new ArrayList<String>() ; // 返回空的 List集合
Collections.addAll(all,"MLDN","LXH","mldnjava") ;
Iterator<String> iter = all.iterator() ;
while(iter.hasNext()){
System.out.print(iter.next() + "、") ;
}
}
};
import java.util.Collections ;
import java.util.List ;
import java.util.ArrayList ;
import java.util.Iterator ;
public class CollectionsDemo03{
public static void main(String args[]){
List<String> all = new ArrayList<String>() ; // 返回空的 List集合
Collections.addAll(all,"MLDN","LXH","mldnjava") ;
Collections.reverse(all) ; // 内容反转
Iterator<String> iter = all.iterator() ;
while(iter.hasNext()){
System.out.print(iter.next() + "、") ;
}
}
};
import java.util.Collections ;
import java.util.List ;
import java.util.ArrayList ;
import java.util.Iterator ;
public class CollectionsDemo04{
public static void main(String args[]){
List<String> all = new ArrayList<String>() ; // 返回空的 List集合
Collections.addAll(all,"MLDN","LXH","mldnjava") ;
int point = Collections.binarySearch(all,"LXH") ; // 检索数据
System.out.println("检索结果:" + point) ; }
};
import java.util.Collections ;
import java.util.List ;
import java.util.ArrayList ;
import java.util.Iterator ;
public class CollectionsDemo05{
public static void main(String args[]){
List<String> all = new ArrayList<String>() ; // 返回空的 List集合
Collections.addAll(all,"MLDN","LXH","mldnjava") ;
if(Collections.replaceAll(all,"LXH","李兴华")){// 替换内容
System.out.println("内容替换成功!") ;
}
System.out.print("替换之后的结果:") ;
System.out.print(all) ; }
};
import java.util.Collections ;
import java.util.List ;
import java.util.ArrayList ;
import java.util.Iterator ;
public class CollectionsDemo06{
public static void main(String args[]){
List<String> all = new ArrayList<String>() ; // 返回空的 List集合
Collections.addAll(all,"1、MLDN","2、LXH","3、mldnjava") ;
Collections.addAll(all,"B、www.mldn.cn") ;
Collections.addAll(all,"A、www.mldnjava.cn") ;
System.out.println("排序之前的集合:" + all) ;
Collections.sort(all) ;
System.out.println("排序之后的集合:" + all) ; }
};
import java.util.Collections ;
import java.util.List ;
import java.util.ArrayList ;
import java.util.Iterator ;
public class CollectionsDemo07{
public static void main(String args[]){
List<String> all = new ArrayList<String>() ; // 返回空的 List集合
Collections.addAll(all,"1、MLDN","2、LXH","3、mldnjava") ;
System.out.println("交换之前的集合:" + all) ;
Collections.swap(all,0,2) ;
System.out.println("交换之后的集合:" + all) ; }
};