Sort Arrays and Collections Java

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

import org.testng.annotations.Test;

/**
* @author asharda
*
*/
public class TestArray {

/**
* Sort Array
*/
@Test
public void testArray()
{
String[] colors={“red”,”green”,”black”,”yellow”};
Arrays.sort(colors);
for(String color:colors)
System.out.println(color);

}

/**
* Sort Collections.
*/
@Test
public void testCollections()
{
ArrayList<String> list=new ArrayList<String>();
list.add(“black”);
list.add(“red”);
list.add(“green”);
list.add(“yellow”);
Collections.sort(list);
for(String color:list)
System.out.println(color);
}

}

Advertisements

About qainterviews

Software Geek,QA Expert,Blogger
This entry was posted in Java, Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s