Three ways for Java to traverse collections
•
Java
For traversing a collection to get its objects, three simple ways are summarized here
Method 1: change the collection into an array, and then traverse the array
Method 2: get () method. But it can only be used in the list collection. Only the list collection has index values.
Method 3: through iterator
Here are two cases to compare
Collection case:
List case:
The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. At the same time, I also hope to support a lot of programming tips!
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码