Write a Java program to sort a given array list

Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..

import java.util.*;
  public class Javacollectionexcercise {
  public static void main(String[] args) {
  // Creae a list and add some colors to the list
  List<String> Stringslist = new ArrayList<String>();
  Stringslist.add("Honda");
  Stringslist.add("Hyundai");    
  Stringslist.add("Bugatti");
  Stringslist.add("Ford");
  Stringslist.add("Audi");
  Stringslist.add("BMW");
 
  System.out.println("List before sort: "+Stringslist);
  Collections.sort(Stringslist);
  System.out.println("List after sort: "+Stringslist);    
 }
}

Result

Write a Java program to sort a given array list
Write a Java program to sort a given array list

Leave a Comment