 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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-sensitive order
An array can be sorted in case-sensitive order using the java.util.Arrays.sort() method. Only a single argument required in this case for this method i.e. the array to be sorted. A program that demonstrates this is given as follows −
Example
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);       System.out.print("The sorted array in case-sensitive order is: ");       System.out.println(Arrays.toString(arr));    } }  Output
The unsorted array is: [apple, mango, Banana, Melon, orange] The sorted array in case-sensitive order is: [Banana, Melon, apple, mango, 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() method is used to sort the array in case-sensitive order. Then the sorted array is displayed. A code snippet which demonstrates this is as follows −
Arrays.sort(arr); System.out.print("The sorted array in case-sensitive order is: "); System.out.println(Arrays.toString(arr));Advertisements
 