sorting in java?? don't spam
Answers
Answer:
Sorting in Java
There are two in-built methods to sort in Java.
Arrays.Sort() works for arrays which can be of primitive data type also.
// A sample Java program to demonstrate working of
// Arrays.sort().
// It by default sorts in ascending order.
import java.util.Arrays;
public class GFG {
public static void main(String[] args)
{
int[] arr = { 13, 7, 6, 45, 21, 9, 101, 102 };
Arrays.sort(arr);
System.out.printf("Modified arr[] : %s",
Arrays.toString(arr));
}
}
Output:
Modified arr[] : [6, 7, 9, 13, 21, 45, 101, 102]
Collections.sort() works for objects Collections like ArrayList and LinkedList.
// Java program to demonstrate working of Collections.sort()
import java.util.*;
public class GFG {
public static void main(String[] args)
{
// Create a list of strings
ArrayList<String> al = new ArrayList<String>();
al.add("Geeks For Geeks");
al.add("Friends");
al.add("Dear");
al.add("Is");
al.add("Superb");
/* Collections.sort method is sorting the
elements of ArrayList in ascending order. */
Collections.sort(al);
// Let us print the sorted list
System.out.println("List after the use of"
+ " Collection.sort() :\n" + al);
Definition: Sorting means to put data in order; either numerically or alphabetically. There are many times when it is necessary to put an array in order from highest to lowest (descending) or vice versa (ascending).Types of Sorting Algorithms:
Bubble Sort. Merge Sort. Insertion Sort.
Explanation:
please Mark as brainlist
Answer:
Sorting is the process of arranging the elements of an array so that they can be placed either in ascending or descending order.