
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
- Related Questions & Answers
- Sort subset of array elements in Java
- Creating a string from a subset of the array elements in Java
- C++ Program to Sort an Array of 10 Elements Using Heap Sort Algorithm
- Java Program to sort Short array
- Java program to Sort long Array
- Program to sort array by increasing frequency of elements in Python
- How to sort Java array elements in ascending order?
- Python program to sort the elements of an array in ascending order
- Python program to sort the elements of an array in descending order
- How to add together a subset of elements of an array in MongoDB aggregation?
- How to sort an array of objects containing null elements in java?
- Java program for Multiplication of Array elements.
- Sort Array of numeric & alphabetical elements (Natural Sort) JavaScript
- Java Program to sort integers in unsorted array
- C program to sort an array of ten elements in an ascending order
Advertisements