![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 long Array
To sort long array in Java, use the Arrays.sort() method. Let’s say the following is our long array.
long[] arr = new long[] { 987, 76, 5646, 96,8768, 8767 };
To sort the above long array is an easy task in Java. Use the following method.
Arrays.sort(arr);
After that, print the array and you can see that it is sorted.
for (long l : arr) { System.out.println(l); }
The following is the complete example.
Example
import java.util.*; public class Demo { public static void main(String []args) { long[] arr = new long[] { 987, 76, 5646, 96,8768, 8767 }; System.out.println("Unsorted long array:"); for (long l : arr) { System.out.println(l); } System.out.println("Sorted long array:"); Arrays.sort(arr); for (long l : arr) { System.out.println(l); } } }
Output
Unsorted long array: 987 76 5646 96 8768 8767 Sorted long array: 76 96 987 5646 8767 8768
Advertisements