How to sort the Web table data in Ascending or Descending using selenium.

 

Step 1 : Read the data from webtable and store in Arraylist.

 

import java.util.*;

public class WebtableDataSort
{
public static void main(String[] args)
{
// Create a list of strings
ArrayList<String> al = new ArrayList<String>();
al.add(“ABC”);
al.add(“LMN”);
al.add(“123”);
al.add(“XYZ”);
al.add(“ABC123”);
al.add(“789”);

/* Collections.sort method is sorting the
elements of ArrayList in ascending order. */
Collections.sort(al);
// Let us print the sorted list
System.out.println(“Assending order Collection.sort() : ” + al);

Collections.reverse(al);
// Let us print the sorted list
System.out.println(“Descending Order Collection.sort() : ” + al);
}
}

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s