
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
What Does the Method sort(obj a) Do in Java
The sort(Object[]) method of the java.util.Arrays class sorts the specified array of Objects into ascending order according to the natural ordering of its elements.
Example
import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { Object ob[] = {27, 11, 44}; for (Object number : ob) { System.out.println("Number = " + number); } Arrays.sort(ob); System.out.println("The sorted Object array is:"); for (Object number : ob) { System.out.println("Number = " + number); } } }
Output
Number = 27 Number = 11 Number = 44 The sorted Object array is: Number = 11 Number = 27 Number = 44
Advertisements