JAVA
sort array java
import java. util. Arrays;
Arrays. sort(array);
sort method in java array
import java.util.Arrays;
import java.util.Collections;
class ArraySort {
public static void main(String[] args) {
Integer[] arr = { 5, 2, 1, 8, 10 };
Arrays.sort(arr, Collections.reverseOrder());
for (int values : arr) {
System.out.print(values + ", ");
// 10, 8, 5, 2, 1,
}
}
}
Array Sort java
import java.util.Arrays;
Arrays.sort(/*Enter the name of the Array*/);
sorting java
public class SortingData {
public static void main(String[] args)
{
int[] arr = { 13, 7, 6, 45, 21, 9, 101, 102 };
Arrays.sort(arr);//sort() function
System.out.printf("Modified arr[] : %s",
Arrays.toString(arr));
}
}
Java Sorting Using sort()
import java.util.ArrayList;
import java.util.Collections;
class Main {
public static void main(String[] args) {
// Creating an array list
ArrayList<Integer> numbers = new ArrayList<>();
// Add elements
numbers.add(4);
numbers.add(2);
numbers.add(3);
System.out.println("Unsorted ArrayList: " + numbers);
// Using the sort() method
Collections.sort(numbers);
System.out.println("Sorted ArrayList: " + numbers);
}
}
sort method in java array
import java.util.Arrays;
import java.util.Collections;
class ArraySort {
public static void main(String[] args) {
Integer[] arr = { 5, 2, 1, 8, 10 };
Arrays.sort(arr, Collections.reverseOrder());
for (int values : arr) {
System.out.print(values + ", ");
// 10, 8, 5, 2, 1,
}
}
}
java program to sort an array
import java.util.Arrays;
class GFG {
public static void main(String args[])
{
int[] arr = { 5, -2, 23, 7, 87, -42, 509 };
System.out.println("The original array is: ");
for (int num : arr) {
System.out.print(num + " ");
}
Arrays.sort(arr);
System.out.println("
The sorted array is: ");
for (int num : arr) {
System.out.print(num + " ");
}
}
}
Array Sort java
import java.util.Arrays;
Arrays.sort(/*Enter the name of the Array*/);
Array Sort java
import java.util.Arrays;
Arrays.sort(/*Enter the name of the Array*/);
java sort method
Arrays.sort();//this method is an inbuild function in java
//to sort the array
sort java array
import java. util. Arrays;
// int[] arr = {1,7,3,5};
Arrays.sort(myArr);
java order an array