0

How can use multiple arrays in an enhanced for loop ?

String name[] = {"Ram","ravi","shyam","tushar","shankar"}; int roll[] = {15, 55, 67, 78, 92}; int length = 5; for(int i=0; i<length; i++) { System.out.println(name[i]+" : "+roll[i]); } How can I do the same using enhanced for loop ?

26th Apr 2017, 6:35 AM
Tushar Ranjan Behera
1 Odpowiedź
+ 8
It looks like you should use a HashMap instead of two arrays, because your values seem to be key/value pairs. Here's a tutorial for that: http://beginnersbook.com/2013/12/hashmap-in-java-with-example/ And here you can find an example how to use an enhanced for loop for a HashMap: http://stackoverflow.com/questions/27867598/java-hashmap-put-in-an-enhanced-for-loop-just-like-an-arraylist
26th Apr 2017, 5:27 PM
Tashi N
Tashi N - avatar