View RSS Feed

Advanced Java

Java's Generic For Loop

Rate this Entry
by , 02-18-2012 at 03:40 PM (1584 Views)
Generic consists of “new for loop”, that is known as “for each loop”. New for loop iterates the generic collections and also supports to integrate. Iteration over a List or Generic set is explained by this code:
Generic List gets iterated by this code:

Java Code: This is the code to explain the Generic For Loop
List<String> list = new ArrayList<String>;
for(String aString : list) {
    System.out.println(aString);
}
For loop parenthesis, declaration of a String variable is done. Current & new values are present in this variable, at every iteration.

Generic Set is iterated by this code:
Java Code: This is the code to explain the iteration
Set<String> set = new HashSet<String>;
for(String aString : set) {
    System.out.println(aString);
}

Submit "Java's Generic For Loop" to Facebook Submit "Java's Generic For Loop" to Digg Submit "Java's Generic For Loop" to del.icio.us Submit "Java's Generic For Loop" to StumbleUpon Submit "Java's Generic For Loop" to Google

Categories
Generics

Comments