Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
