Sort double Array - Java Language Basics

Java examples for Language Basics:double

Description

Sort double Array

Demo Code

 
import java.util.Arrays;
 
public class Main {
 
  public static void main(String[] args) {
    double[] d1 = new double[]{3,2,5,4,1};
   /*  w w  w.  ja va  2  s  . c om*/
    System.out.print("Original Array :\t ");
    for(int index=0; index < d1.length ; index++)
      System.out.print("  "  + d1[index]);
   
    //To sort full array use sort(double[] d) method.
    Arrays.sort(d1);
   
    System.out.print("\nSorted double array :\t ");
    for(int index=0; index < d1.length ; index++)
      System.out.print("  "  + d1[index]);
     
    double[] d2 = new double[]{5,2,3,1,4};
    Arrays.sort(d2,1,4);
   
    //print sorted double array
    System.out.print("\nPartially Sorted double array :\t ");
    for(int index=0; index < d2.length ; index++)
      System.out.print("  "  + d2[index]);
 
  }
}

Result


Related Tutorials