Sort long type Array - Java Language Basics

Java examples for Language Basics:long

Description

Sort long type Array

Demo Code


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

Result


Related Tutorials