A
A
Anatoly2015-05-01 11:33:59
Java
Anatoly, 2015-05-01 11:33:59

What is he doing ":"?

Please explain or provide a link. What does ":" do in the last loop?

public class testMethods
{
    public static void main(String[] args) throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        ArrayList<Integer> list = new ArrayList<Integer>();
        for (int i = 0; i < 5; i++)
        {
            list.add(0, Integer.parseInt(reader.readLine()));
        }
        for (int n : list){
            System.out.println(n);
        }

    }
}

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Rikcon, 2015-05-01
@Anatol_s

This is foreach as far as I understood
stackoverflow.com/questions/1818729/java-foreach-l...

[
[email protected]><e, 2015-05-01
@barmaley_exe

This is a for-each loop . Designed to iterate over containers so you don't have to mess around with iterators.

B
buksttabu, 2015-05-01
@buksttabu

This is a loop for arrays.
n[i] = list[i]

O
olexandr7, 2015-05-02
@olexandr7

This is a loop where each element of the List array is passed to the variable n, and since the type in the array is numeric, the variable n is also made of a numeric type

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question