![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 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
Advertisements