- 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 Short array
To sort Short array, use the Arrays.sort() method.
Let us first declare and initialize an unsorted Short array.
short[] arr = new short[] { 35, 25, 18, 45, 77, 21, 3 };
Now, let us short the array.
Arrays.sort(arr);
The following is the complete example that shows how to sort Short array in Java.
Example
import java.util.*; public class Demo { public static void main(String []args) { short[] arr = new short[] { 35, 25, 18, 45, 77, 21, 3 }; System.out.println("Unsorted:"); for (short s : arr) { System.out.println(s); } System.out.println("Sorted:"); Arrays.sort(arr); for (short s : arr) { System.out.println(s); } System.out.println(); } }
Output
Unsorted: 35 25 18 45 77 21 3 Sorted: 3 18 21 25 35 45 77
Advertisements