复制代码
- //:Unsupported.java
- //SometimesmethodsdefinedintheCollection
- //interfacesdontwork!
- packagec08.newcollections;
- importjava.util.*;
- publicclassUnsupported{
- privatestaticString[]s={
- "one","two","three","four","five",
- "six","seven","eight","nine","ten",
- };
- staticLista=Arrays.toList(s);
- staticLista2=Arrays.toList(
- newString[]{s[3],s[4],s[5]});
- publicstaticvoidmain(String[]args){
- Collection1.print(a);//Iteration
- System.out.println(
- "a.contains("+s[0]+")="+
- a.contains(s[0]));
- System.out.println(
- "a.containsAll(a2)="+
- a.containsAll(a2));
- System.out.println("a.isEmpty()="+
- a.isEmpty());
- System.out.println(
- "a.indexOf("+s[5]+")="+
- a.indexOf(s[5]));
- //Traversebackwards:
- ListIteratorlit=a.listIterator(a.size());
- while(lit.hasPrevious())
- System.out.print(lit.previous());
- System.out.println();
- //Settheelementstodifferentvalues:
- for(inti=0;i<a.size();i++)
- a.set(i,"47");
- Collection1.print(a);
- //Compiles,butwontrun:
- lit.add("X");//Unsupportedoperation
- a.clear();//Unsupported
- a.add("eleven");//Unsupported
- a.addAll(a2);//Unsupported
- a.retainAll(a2);//Unsupported
- a.remove(s[0]);//Unsupported
- a.removeAll(a2);//Unsupported
- }
- }///:~
欢迎光临 仓酷云 (http://ckuyun.com/) | Powered by Discuz! X3.2 |