- Trending Categories
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
- Related Articles
- Java Program to sort Short array
- Java Program to sort integers in unsorted array
- Java Program to Sort 2D Array Across Columns
- Java Program to implement Binary Search on long array
- Java Program to fill elements in a long array
- Java Program to sort a subset of array elements
- Java Program to sort an array in alphabetical order
- Java Program to Sort 2D Array Across Left Diagonal
- How to convert Long array list to long array in Java?
- Java Program to sort an array in case-insensitive order
- Java Program to sort an array in case-sensitive order
- Java Program to Sort Array list in an Ascending Order
- Java Program to Sort the Array Elements in Descending Order
- Golang Program To Sort An Array
- C program to sort an array by using merge sort

Advertisements