Answers for "iterate array java"

0

iterator for array java

import java.util.Arrays;
import java.util.Iterator;

public class ArrayToIterable {
   public static void main(String args[]){
      Integer[] myArray = {897, 56, 78, 90, 12, 123, 75};
      Iterator<Integer> iterator = Arrays.stream(myArray).iterator();
      while(iterator.hasNext()) {
         System.out.println(iterator.next());
      }
   }
}
Posted by: Guest on May-28-2020
4

loop through array java

import java.util.*;

public class HelloWorld {
  public static void main(String[] args) {
    
    // you can define the type of list you want to init - String int etc inside <yourType> eg. <String>
    List<String> family = new ArrayList();
    
    family.add("Member1");
    family.add("Member2");
    family.add("Member3");
    family.add("Member4");
    family.add("Member5");
    
    // print array 
    for(String name : family)
    {
    	System.out.println(name);
    }
    
 
  }
}
Posted by: Guest on March-10-2020
1

Java loop array

Scanner scanner = new Scanner( System.in );
        int n = scanner.nextInt();
        int[] a=new int[ n + 1 ];
        for( int k = 1; k <= n; k ++ ){
            a[ k ] = scanner.nextInt();
        }
        Arrays.sort( a );
        for( int k = 1; k <= n; k ++ ){
            System.out.print( a[k] + " " );
        }
Posted by: Guest on August-04-2021
1

java loop through array

class LoopThroughArray {
	public static void main(String[] args)
	{

		int[] myArr = {1, 2, 3, 4};

		for(int i : myArr){

			System.out.println(i + "\n")

		}

		/* Output:
		1
		2
		3
		4
		*/

	}
}
Posted by: Guest on August-31-2020
0

java loop through array

String[] elements = {"a", "a", "a", "a"};   
for (String s: elements) {           
    //Do your stuff here
    System.out.println(s); 
}
Posted by: Guest on October-01-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language