How to declare and use ArrayList<> of String 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 ");
        
      System.out.println(str);
    }

}


/*
run:

[abc , xyz , uvw , def ]

*/

 



answered Sep 3, 2016 by avibootz

Related questions

1 answer 173 views
1 answer 108 views
1 answer 165 views
1 answer 176 views
1 answer 170 views
...