Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Enhanced For Loop

As of Java 5, the enhanced for loop was introduced. This is mainly used to traverse collection of elements including arrays. 

Syntax : 
for(declaration : expression) {
   // Statements
}
Declaration − The newly declared block variable, is of a type compatible with the elements of the array you are accessing. The variable will be available within the for block and its value would be the same as the current array element.
Expression − This evaluates to the array you need to loop through. The expression can be an array variable or method call that returns an array.
Comment

Enhanced For Loop Java

class Main {
   public static void main(String args[]){
      int arr[]={1,2,3,4,5};
      for (int num : arr) {
         System.out.println(num);
      }
   }
}
Comment

enhanced for loop java

 for(int name: array)
        {
            System.out.print(name + " ");
        }
Comment

enhanced 4 loop

for (int myValue : myArray) {
    System.out.println(myValue);
}
Comment

enhanced 4 loop

for (int i = 0; i < myArray.length; i++) {
    System.out.println(myArray[i]);
}
Comment

enhanced for loops

String[] myArray = {"Enhanced for loops", "are cool", "and save time!"};

for (String myValue : myArray) {
    System.out.println(myValue);
}

/*Result:
Enhanced for loops
are cool
and save time!
*/
Comment

PREVIOUS NEXT
Code Example
Java :: odd numbers in java 
Java :: what is method overriding in java 
Java :: Caused by: android.view.InflateException: Binary XML file line 
Java :: java function 
Java :: autowired in spring 
Java :: how to make a for loop increment by 2 in java 
Java :: Java if...else...if Statement 
Java :: string split java 
Java :: java android join array list 
Java :: what is operator overloading in java 
Java :: how to get stack trace of a function in java 
Java :: javafx access fxml elements 
Java :: types of classes in java 
Java :: java string extract words 
Java :: maven set repository location command line 
Java :: postfix operator in java 
Java :: /bin/sh 1 java not found docker 
Java :: java non-breajubg soace remove 
Java :: bootstrap error message 
Sql :: stop mysql server mac 
Sql :: convert utc to est sql 
Sql :: freemysqlhosting keeps deleting tables 
Sql :: list all triggers in sql server 
Sql :: mysql CURRENT_TIMESTAMP() 
Sql :: list tables sqlite 
Sql :: query to find table size in oracle 12c 
Sql :: sql delete multiple ids 
Sql :: drop view in mysql 
Sql :: rename column postgres 
Sql :: oracle show running job 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =