- 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 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
To Continue Learning Please Login
Login with Google