
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Sort Array Using sort(Object[], int, int) Method in Java
The java.util.Arrays.sort(Object[] a, int fromIndex, int toIndex) method sorts the specified range of the specified array of objects into ascending order, according to the natural ordering of its elements. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive.
Example
import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { Object ob[] = {27, 11, 5, 44}; for (Object number : ob) { System.out.println("Number = " + number); } Arrays.sort(ob, 1, 3); System.out.println("Object array with some sorted values(1 to 3) is:"); for (Object number : ob) { System.out.println("Number = " + number); } } }
Output
Number = 27 Number = 11 Number = 5 Number = 44 Object array with some sorted values(1 to 3) is: Number = 27 Number = 5 Number = 11 Number = 44
Advertisements