- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to sort an array in case-insensitive order
An array can be sorted in case-insensitive order using the java.util.Arrays.sort() method. Also the java.text.Collator class is required as Collator.getInstance() is used to obtain the Collator object for the required locale.
A program that demonstrates this is given as follows −
Example
import java.text.Collator; import java.util.Arrays; public class Demo { public static void main(String args[]) { String[] arr = new String[] { "apple", "mango", "Banana", "Melon", "orange" }; System.out.print("The unsorted array is: "); System.out.println(Arrays.toString(arr)); Arrays.sort(arr, Collator.getInstance()); System.out.print("The sorted array in case-insensitive order is: "); System.out.println(Arrays.toString(arr)); } }
Output
The unsorted array is: [apple, mango, Banana, Melon, orange] The sorted array in case-insensitive order is: [apple, Banana, mango, Melon, orange]
Now let us understand the above program.
First the array arr[] is defined. Then the unsorted array is printed. A code snippet which demonstrates this is as follows −
String[] arr = new String[] { "apple", "mango", "Banana", "Melon", "orange" }; System.out.print("The unsorted array is: "); System.out.println(Arrays.toString(arr));
The Arrays.sort(arr, Collator.getInstance()) method is used to sort the array in a case-insensitive order. Then the sorted array is displayed. A code snippet which demonstrates this is as follows −
Arrays.sort(arr, Collator.getInstance()) System.out.print("The sorted array in case-insensitive order is: "); System.out.println(Arrays.toString(arr));
- Related Articles
- Java Program to sort a List in case insensitive order
- Java Program to sort an array in case-sensitive order
- Java Program to sort an array in alphabetical order
- Java Program to Sort Array list in an Ascending Order
- Java Program to sort a List in case sensitive order
- C program to sort an array in an ascending order
- C# program to sort an array in descending order
- C program to sort an array in descending order
- Golang Program To Sort An Array In Ascending Order Using Insertion Sort
- Golang Program to sort an array in descending order using insertion sort
- 8086 program to sort an integer array in ascending order
- 8086 program to sort an integer array in descending order
- C program to sort an array of ten elements in an ascending order
- JavaScript filter an array of strings, matching case insensitive substring?
- Python program to sort the elements of an array in ascending order

Advertisements