Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use for each in java

    • 0
    • 1
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 204
    Comment on it

    Using for each In place of Normal loops in java

    for each can be used to display the all the elements of the array.

    Syntax :

    for(datatype variablename : array)
    {
    // Do the work with varialble
    }
    

    example

        public class Main {
           public static void main(String[] args) {
              int[] intary = { 1,2,3,4};
           System.out.println("Elements::");
           for(int x :intary)
           {
                   System.out.print(x+" ");  
           }
        }
    //output : 
    //Elements::1 2 3 4
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: