logoNEURAL COOK
SearchAll PostsTagsNotesAuthor
logoNEURAL COOK

A posts created with Next.js and Tailwind.css

Explore

  • All posts
  • Notes
  • Snippets
  • Tags
  • RSS feed

Connect

instagramtwitterfacebookyoutubelinkedinmailgithub

© 2026 VIKI. All rights reserved.

Built with
Contents
ArraysData StructuresListMath OperationBinary SearchSortingString Operation
Snippets/java

Sorting

1 min read
On this pageArrays
ArraysList

# Arrays

To sort an array use

Arrays.sort(arr); // Sorts the array in ascending order

To sort an array in descending order

Arrays.sort(arr,Collections.reverseOrder());

this only works for non-primitive array i.e Integer [] array not int [] array

If we want to sort array from some index to some index use

Arrays.sort(arr,fromIndex,toIndex);

If its a multi-dimensional array

Arrays.sort(arr, (a, b) -> Integer.compare(a[column],b[column]));

to sort an array with custom comparator

CustomComparator implements Comparator<T> {
    public int compare(T c1, T c2)
     {
         // return -1, 0, +1
     }
}

# List

To sort a list use

Collections.sort(list);
←PreviousBinary SearchNext→String Operation

On this page

ArraysList