Using the foreach Action array
foreach is not a keyword in Java, it is a special simplified version of A for statement, which is simpler and easier to iterate through arrays and collections. In terms of the literal meaning of foreach, which means "for each", how do you use a foreach statement?
Grammar:
650) this.width=650; "src=" http://img.mukewang.com/53940fb30001445a02820079.jpg "/>
We use the for and foreach statements to iterate through the array, respectively.
650) this.width=650; "src=" http://img.mukewang.com/53941065000119a407790392.jpg "/>
Operation Result:
650) this.width=650; "src=" http://img.mukewang.com/5394110800016dd303630250.jpg "/>
It's easy to see the foreach!!
Leave a question to everyone: what if you want to get the subscript for an array element in a foreach statement??
Code:
Import Java.util.Arrays;
public class HelloWorld {
public static void Main (string[] args) {
Define an integer array and save the score information
Int[] Scores = {89, 72, 64, 58, 93};
Sorting an array of arrays classes
Arrays.sort (scores);
Iterating through the elements in the output array using foreach
for (int score:scores) {
SYSTEM.OUT.PRINTLN (score);
}
}
}
Operation Result:
58
64
72
89
93
This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1547987
Java Foundation---Using the foreach operation Array (33)