Java Sort Byte Array
Chapter:
Data Structures
Last Updated:
19-09-2016 16:10:36 UTC
Program:
/* ............... START ............... */
import java.util.Arrays;
public class JavaSortByteArray {
public static void main(String[] args) {
byte[] b1 = new byte[] { 3, 2, 5, 4, 1 };
System.out.print("Original Array :\t ");
for (int index = 0; index < b1.length; index++)
System.out.print(" " + b1[index]);
Arrays.sort(b1);
System.out.print("\nSorted byte array :\t ");
for (int index = 0; index < b1.length; index++)
System.out.print(" " + b1[index]);
byte[] b2 = new byte[] { 5, 2, 3, 1, 4 };
Arrays.sort(b2, 1, 4);
System.out.print("\nPartially Sorted byte array :\t ");
for (int index = 0; index < b2.length; index++)
System.out.print(" " + b2[index]);
}
}
/* ............... END ............... */
Output
Original Array : 3 2 5 4 1
Sorted byte array : 1 2 3 4 5
Partially Sorted byte array : 5 1 2 3 4
Tags
Sort Byte Array, Java, Data Structures