How to create nested collection in Java

1 Answer

0 votes
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collection;

public class MyClass {
    public static void main(String args[]) {
        Collection<List<String>> co = new ArrayList<>();
                co.add(Arrays.asList("java", "c", "c++", "rust"));
                co.add(Arrays.asList("c#", "python", "php"));

        System.out.println(co);
    }
}
  
  
  
  
/*
run:
  
[[java, c, c++, rust], [c#, python, php]]
  
*/

 



answered Mar 12, 2023 by avibootz

Related questions

...