0% found this document useful (0 votes)
10 views1 page

India Example

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

India Example

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

package list;

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

public class IndiaExample {

public static void main(String[] args) {

List<String> mh = new ArrayList();


mh.add("Pune");
mh.add("Mumbai");
System.out.println(mh);

List<String> gj = new ArrayList();


gj.add("Surat");
gj.add("GandhiNagar");
System.out.println(gj);

List<List<String>> india = new ArrayList();


india.add(mh);
india.add(gj);

System.out.println(india);

Iterator<List<String>> iterator = india.iterator();

while (iterator.hasNext()) {
List<String> state = iterator.next();
Iterator<String> iterator2 = state.iterator();
while (iterator2.hasNext()) {
String city = iterator2.next();
System.out.println(city);
}
}

System.out.println("For each loop");

for (List<String> state1 : india) {

for (String city : state1) {


System.out.println(city);
}
}

}
}

You might also like