go to previous page   go to home page   go to next page

Answer:

Of course.


Sorting an Array of double

Here is a demo program that shows Arrays.sort() used with an array of double. The Arrays.sort() is overloaded, so there is a version that sorts arrays of most primitive types.

import java.util.*;

public class ArraysTesterDouble
{
  
  public static void main ( String[] args )
  {
    final int SIZE = 100;
    double[] values  = new double[ SIZE ];
    
    // initialize the array
    for ( int j=0; j< SIZE; j++ )
      values[j] = Math.sin( 17*j ) * Math.sin( 23*j );
    
    // print out the array
    System.out.println("Before: "); 
    for ( double val : values )
      System.out.print( val + ", " ); 
    
    // sort the array
    Arrays.sort( values );
  
    // print out the array
    System.out.println("\nAfter: "); 
    for ( double val : values )
      System.out.print( val + ", " ); 
    System.out.println( );
 
   }
}

QUESTION 13:

Could an array of byte be sorted?


go to previous page   go to home page   go to next page