Here is the coding example.
import java.util.ArrayList; import java.util.Collections; import java.util.List; public class CollectionSort { public static void main (String[] args){ List<String> names = new ArrayList<String>(); names.add("Nimal"); names.add("Sunil"); names.add("Tharaka"); names.add("Isuru"); names.add("Suresh"); names.add("Anuradha"); names.add("Thilak"); Collections.sort(names); int i=1; for(String name:names) System.out.println("item "+i+++" "+name); } }
Output for this code will be like this.
item 1 Anuradha
item 2 Isuru
item 3 Nimal
item 4 Sunil
item 5 Suresh
item 6 Tharaka
item 7 Thilak
A simple useful article. continue writing.. hope to see more.
ReplyDeleteThanx Rob
Delete