数组转换的不可调用

数组转换的不可调用

方法不可调用
import  java.util. * ;

public   class  Unsupported  {
  
static  List a  =  Arrays.asList(     //----〉Arrays被转换成为List类,List类中方法被禁用
    
" one two three four five six seven eight " .split( "   " ));
  
static  List a2  =  a.subList( 3 6 );
  
public   static   void  main(String[] args)  {
    System.out.println(a);
    System.out.println(a2);
    System.out.println(
" a.contains( "   +  a.get( 0 +   " ) =  "   +
      a.contains(a.get(
0 )));
    System.out.println(
" a.containsAll(a2) =  "   +
      a.containsAll(a2));
    System.out.println(
" a.isEmpty() =  "   +  a.isEmpty());
    System.out.println(
" a.indexOf( "   +  a.get( 5 +   " ) =  "   +
      a.indexOf(a.get(
5 )));
    
//  Traverse backwards:
    ListIterator lit  =  a.listIterator(a.size());
    
while (lit.hasPrevious())
      System.out.print(lit.previous() 
+   "   " );
    System.out.println();
    
//  Set the elements to different values:
     for ( int  i  =   0 ; i  <  a.size(); i ++ )
      a.set(i, 
" 47 " );
    System.out.println(a);
    
//  Compiles, but won't run:
    lit.add( " X " );  //  Unsupported operation
    a.clear();  //  UnsupportedList类中方法被禁用
    a.add( " eleven " );  //  Unsupported
    a.addAll(a2);  //  Unsupported
    a.retainAll(a2);  //  Unsupported
    a.remove(a.get( 0 ));  //  Unsupported
    a.removeAll(a2);  //  Unsupported
  }

}
  // /:~

你可能感兴趣的:(数组转换的不可调用)