arraysortexample.java

来自「程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件」· Java 代码 · 共 42 行

JAVA
42
字号
package examples.collections;

import java.util.*;

/** A class to demonstrate the use of the sort and
  * search algorithms in the java.util package
  */
public class ArraySortExample {
   /** Test method for the class
     * @param args not used
     */
   public static void main( String[] args ) {
      // create a list and intialize it
      Object[] data = {  new Double( 3.45 ),
                         new Double( -0.2 ),
                         new Double( 100.3 ),
                         new Double( 89.67 ),
                         new Double( 11.0 ),
                         new Double( 23.132 )
                      };
      List list = Arrays.asList( data );

      // iterate to display the set values
      Iterator i1 = list.iterator();
      while ( i1.hasNext() ) {
         System.out.print( i1.next() + " " );
      }
      System.out.println();

      Collections.sort( list );
      Iterator i2 = list.iterator();
      while ( i2.hasNext() ) {
         System.out.print( i2.next() + " " );
      }
      System.out.println();

      for( int j=0; j<data.length; j++ ) {
         System.out.print( data[j] + " " );
      }
      System.out.println();
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?