Share on Google+Share on Google+

Iterator Java Sort

In this section of tutorial we will learn how to use the static sort() method .We will create an example and sort the ArrayList.Then display the contents of the sorted ArrayList.

  • Sort is a static method of the Collections class.
  • It sorts the contents of the list Collection.

Example of Java Sort Iterator
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class sort {

	public static void main(String[] args) {
		List list = new ArrayList();
		String country[] = { "India", "Japan", "USA", "UK", "Nepal" };
		for (int i = 0; i < 5; i++) {
		Iterator i = list.iterator();

		while (i.hasNext()) {
			System.out.print( + "\t");


India Japan Nepal UK USA


Posted on: November 4, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null