How to print ArrayList<> with forEach in Java

1 Answer

0 votes
package javaapplication1;

import java.util.List;
import java.util.ArrayList;

public class JavaApplication1 {

    public static void main(String[] args) {

      List<String> str = new ArrayList<>();
      str.add("abc ");
      str.add("xyz ");
      str.add("uvw ");
      str.add("def ");
      
      str.forEach(System.out::println);
    }
}


/*
run:

abc 
xyz 
uvw 
def 

*/

 



answered Sep 3, 2016 by avibootz

Related questions

1 answer 225 views
2 answers 225 views
225 views asked Sep 29, 2019 by avibootz
1 answer 197 views
1 answer 104 views
1 answer 197 views
197 views asked Mar 22, 2021 by avibootz
...