Special for loop in java: use of foreach

Source: Internet
Author: User
Tags sorts

The first format is:

 for (element Type element variable: traversal Object) {    executed code}

For example:

public class Test {public        static void main (string[] Args) {        //define an integer array, save score Information int[] scores = {89, 72, 64, 58, 93 };        Sorts the array of arrays classes Arrays.sort (scores);        Use foreach to iterate through the elements in the output array for (int sco:scores) {System.out.println (sco);}}}

Here's a hint: to call this, you'll Import the package

Import java.util.Arrays;
sorts the array of Arrays classes arrays.sort (scores);

This is sorted by array.

The output is This:

Special for loop in java: use of foreach

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: info-contact@alibabacloud.com 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.