Sunday, November 26, 2017

JAVA - How to go through an array

Several method:

Variant 1

String[] array = new String[3];

array[0] = "One";
array[1] = "Two";
array[2] = "Three";

for ( int i = 0; i < array.length; i++ )
  System.out.println( array[i] );
Output is:
One 
Two 
Three 
Variant 2

String[] array = new String[3];

array[0] = "One";
array[1] = "Two";
array[2] = "Three";

for ( String item : array )
  System.out.println( item );

NOTE: Every next loop is into item variable filled next array item.

No comments:

Post a Comment