foreach in Java, used to iterate through an array

Source: Internet
Author: User
Here for is a foreach in Java,   used to iterate over the array.
for (int i:d) is the data that iterates through the array d of the int type every time you access it, put it in the int type I.
and for (int i=0;i<d.length (); i++) are the same, but there are more available cases of foreach.

public class E1 {
public static void Main (string[] args) {
Int[]d=new int[] {1,2,3,4,64,1234,3124,657,22};
System.out.println ("d.length=" +d.length);
for (int i:d) {
System.out.println (i);

foreach in Java, used to iterate through an array

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.