1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| public static void main(String[] args)
{
String[] firstNames =
{
"Marge", "Homer", "Lisa", "Bart", "Maggie"
};
System.out.println("- With for loop:");
for (int i = 0; i < firstNames.length; i++)
{
System.out.println(firstNames[i]);
}
System.out.println("- With foreach loop");
for (String name : firstNames)
{
System.out.println(name);
}
} |
public static void main(String[] args)
{
String[] firstNames =
{
"Marge", "Homer", "Lisa", "Bart", "Maggie"
};
System.out.println("- With for loop:");
for (int i = 0; i < firstNames.length; i++)
{
System.out.println(firstNames[i]);
}
System.out.println("- With foreach loop");
for (String name : firstNames)
{
System.out.println(name);
}
}