[Java] How to output standard output from array with forEach

less than 1 minute read

How to output standard output from array with forEach. The contents of array a are received in variable i, array elements are given by the add method, and standard output is performed sequentially with forEach.

import java.util.*;

public class Main {
     public static void main(String[] args) throws Exception {
         String[] a = {"blue", "village", "wise"};
        
         ArrayList<String> numbersList = new ArrayList<>();
        
         for(String i :a) {
             numbersList.add(i);
         }
        
         numbersList.stream().forEach((i) -> {System.out.print(i); });
        
     }
}

Tags:

Updated: