Amazing technological breakthrough possible @S-Logix

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • +91- 81240 01111

Social List

How to sort numbers list of items in java?


This program shows how to sort the integer and string using sort method of Arrays class that sorts the elements in natural order (Integer-ascending order, String-Alphabetical order). As the sort method is static the input array is modified instead of creating new array. Sorted elements can be accessed using enhanced for loop.

Sample Code
  • Filename:

import java.util.*;
class Sorting {
public static void main(String args[]) {
//Sorting Integer in natural order
int n[] = {40,20,29,65,74};
System.out.println("Sorted list of Integer");
for(int i:n) {
//Sorting String in natural order
String s[] = {"dog","cat","animal","bird","dove"};
System.out.println("Sorted list of String");
for(String i:s) {


Sort numbers list of items in java