 
 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 a subset of array elements
Let us first create a string array −
String[] strArr = new String[] { "r", "p", "v","y", "s", "q" };
Now, use Arrays.sort() to get the subset. Use the following to sort only from the index range 2 to 6.
Arrays.sort(strArr, 2, 6);
Example
import java.util.Arrays;
public class Demo {
   public static void main(String[] args) {
      String[] strArr = new String[] { "r", "p", "v","y", "s", "q" };
      Arrays.sort(strArr, 2, 6);
      System.out.println("Sorted subset of array elements from index 2 to 6...");
      for (int a = 0; a < strArr.length; a++) {
         System.out.println(strArr[a]);
      }
   }
}
Output
Sorted subset of array elements from index 2 to 6... r p q s v y
Advertisements
                    