Sample Test to Test For Each and Iterator

import java.util.ArrayList;
import java.util.Iterator;

/**In this test we have a sample Array List that we will print using for each and Iterator in Java*/
public class sampletest {

/**This function is going to test that Iterator works
* @expectedResult:Iterator works
* @throws Exception
*/
public static void testIterator() throws Exception
{
ArrayList<String> ar=new ArrayList<String>();
ar.add(“Cats”);
ar.add(“and”);
ar.add(“dog”);
Iterator<String> it=ar.listIterator();
System.out.println(“Contents of the String are”);
while(it.hasNext())
{
System.out.println(it.next());
}

}

public static void testforeach()
{
ArrayList<String> ar=new ArrayList<String>();
ar.add(“Cats”);
ar.add(“and”);
ar.add(“dog”);
System.out.println(“Contents of the String in for each method are”);
for(String s:ar)
{
System.out.println(s);
}
}
/**This function is going to test that for each method works
* @expectedResult:Iterator works
* @throws Exception
*/
public static void main(String args[]) throws Exception
{
testIterator();
testforeach();

}

}

Advertisements

About qainterviews

Software Geek,QA Expert,Blogger
This entry was posted in Uncategorized and tagged , , . 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