๐๐ข๐๐๐๐ซ๐๐ง๐๐ ๐๐๐ญ๐ฐ๐๐๐ง ๐๐ซ๐ซ๐๐ฒ๐ฌ.๐ฌ๐จ๐ซ๐ญ() ๐๐ง๐ ๐๐จ๐ฅ๐ฅ๐๐๐ญ๐ข๐จ๐ง๐ฌ.๐ฌ๐จ๐ซ๐ญ().
๐๐๐ซ๐ซ๐๐ฒ๐ฌ.๐ฌ๐จ๐ซ๐ญ():-It sorts the arrays which can be the type of primitive data type.
๐๐ฅ๐ ๐จ๐ซ๐ข๐ญ๐ก๐ฆ:- Dual-Pivot Quicksort algorithm
๐๐ข๐ฆ๐ ๐๐จ๐ฆ๐ฉ๐ฅ๐๐ฑ๐ข๐ญ๐ฒ: O(nlog(n))ย ย
๐๐ฎ๐ฑ๐ข๐ฅ๐ข๐๐ซ๐ฒ ๐๐ฉ๐๐๐ : O(1)
๐ ๐๐จ๐ฅ๐ฅ๐๐๐ญ๐ข๐จ๐ง๐ฌ.๐ฌ๐จ๐ซ๐ญ():- It sort only the objects which extends List interface(ArrayList,LinkedList etc)ย or user-defind class objects if class implements Comparable.ย
๐๐ฅ๐ ๐จ๐ซ๐ข๐ญ๐ก๐ฆ:- Adaptive Mergesort algorithm
๐๐ข๐ฆ๐ ๐๐จ๐ฆ๐ฉ๐ฅ๐๐ฑ๐ข๐ญ๐ฒ: O(nlog(n))ย ย
๐๐ฎ๐ฑ๐ข๐ฅ๐ข๐๐ซ๐ฒ ๐๐ฉ๐๐๐ : O(1)
Examples:-
โ
Arrays.sort():-
import java.util.Arrays;
class ArraySort {
public static void main(String arg[]){
ย int arr[] = {10,4,6,7,8};
ย Arrays.sort(arr); // {4,6,7,8,10}
ย }
}
โ
Collections.sort():-
import java.util.Collection;
import java.util.List;
class CollectionSort {
public static void main(String arg[]){
ย List<Integer> arrList = List.of(11,5,6,3,2,8)
ย Collections.sort(arrList); // {2,3,5,6,8,11}
ย }
}
Follow
@full_stack_geek ๐จโ๐ป for more interview questions.
#java #corejava #java8 #springboot #backenddeveloper #fullstackdeveloper #javadeveloper #javaprogramming