How to Sort Arrays in Java, Arrays Sorting In Java

Core Java » on Oct 23, 2012 { 2 Comments } By Sivateja

Hi let us see how to sort array of values in java, we can sort the arrays using Arrays class in java.util.*; package. Consider the following example..

package java4s;

import java.util.Arrays;
public class SortArray {

    public static void main(String... args)
            String[] countries = {"India","United States","Malaysia","Australia","Lundon"};

            Arrays.sort(countries); // Countries array values will be sorted here

            for(int i=0;i<countries.length;i++)
                System.out.println("Countries : "+countries[i]);


Countries : Australia
Countries : India
Countries : Lundon
Countries : Malaysia
Countries : United States


You Might Also Like

  ::. About the Author .::

Sivateja Kandula - Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.


2 Responses to “How to Sort Arrays in Java, Arrays Sorting In Java”
  1. babu says:

    very helpful

    I need some more question and ans:
    1)in collection interface
    we write the code allow the duplicate values into set(interface)

  2. nitish jaiswal says:

    how to merge two Array?


By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2024 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.