- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 alphabetical order
Let us first create a string array:
String[] strArr = new String[] { "r", "p", "v","y", "s", "q" };
Now, use the Arrays.sort() method to sort an array in alphabetical order. Here, we have set the order to be case insensitive:
Arrays.sort(strArr, String.CASE_INSENSITIVE_ORDER);
Example
import java.util.Arrays; public class Demo { public static void main(String[] args) { String[] strArr = new String[] { "r", "p", "v","y", "s", "q" }; System.out.println("Sort array in alphabetical order..."); Arrays.sort(strArr, String.CASE_INSENSITIVE_ORDER); for (int a = 0; a < strArr.length; a++) { System.out.println(strArr[a]); } } }
Output
Sort array in alphabetical order... p q r s v y
- Related Articles
- C program to sort names in alphabetical order
- Java Program to sort an array in case-insensitive order
- Java Program to sort an array in case-sensitive order
- Java Program to Sort Array list in an Ascending Order
- C program to sort names in alphabetical order using structures
- C program to sort names in alphabetical order with string functions.
- How to sort an R data frame rows in alphabetical 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
- 8086 program to sort an integer array in descending order
- 8086 program to sort an integer array in ascending order
- Sort the array of strings according to alphabetical order defined by another string in C++
- C program to sort an array of ten elements in an ascending order
- Python program to sort the elements of an array in ascending order

Advertisements