JAVA 8 : How to initialize List Of List in one line [closed]
Hello i want to initialize List Of list in one line
List<List<Integer>> list = .....;
Thanks
java list arraylist
closed as unclear what you're asking by Andy Turner, Roddy of the Frozen Peas, rgettman, khelwood, Shiladitya Nov 14 '18 at 2:31
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
Hello i want to initialize List Of list in one line
List<List<Integer>> list = .....;
Thanks
java list arraylist
closed as unclear what you're asking by Andy Turner, Roddy of the Frozen Peas, rgettman, khelwood, Shiladitya Nov 14 '18 at 2:31
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
There's a very complete answer over here already: stackoverflow.com/a/47288158/236528
– mjuarez
Nov 13 '18 at 21:26
2
What do you want to initialise it to?
– khelwood
Nov 13 '18 at 21:29
add a comment |
Hello i want to initialize List Of list in one line
List<List<Integer>> list = .....;
Thanks
java list arraylist
Hello i want to initialize List Of list in one line
List<List<Integer>> list = .....;
Thanks
java list arraylist
java list arraylist
asked Nov 13 '18 at 21:22
CHARAFI SaadCHARAFI Saad
433517
433517
closed as unclear what you're asking by Andy Turner, Roddy of the Frozen Peas, rgettman, khelwood, Shiladitya Nov 14 '18 at 2:31
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Andy Turner, Roddy of the Frozen Peas, rgettman, khelwood, Shiladitya Nov 14 '18 at 2:31
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
There's a very complete answer over here already: stackoverflow.com/a/47288158/236528
– mjuarez
Nov 13 '18 at 21:26
2
What do you want to initialise it to?
– khelwood
Nov 13 '18 at 21:29
add a comment |
There's a very complete answer over here already: stackoverflow.com/a/47288158/236528
– mjuarez
Nov 13 '18 at 21:26
2
What do you want to initialise it to?
– khelwood
Nov 13 '18 at 21:29
There's a very complete answer over here already: stackoverflow.com/a/47288158/236528
– mjuarez
Nov 13 '18 at 21:26
There's a very complete answer over here already: stackoverflow.com/a/47288158/236528
– mjuarez
Nov 13 '18 at 21:26
2
2
What do you want to initialise it to?
– khelwood
Nov 13 '18 at 21:29
What do you want to initialise it to?
– khelwood
Nov 13 '18 at 21:29
add a comment |
2 Answers
2
active
oldest
votes
List<List<Integer>> list = Arrays.asList(Arrays.asList(1,2), Arrays.asList(3,4));
In Java 9+ you can replace Arrays.asList() with List.of().
add a comment |
List<List<Integer>> list =
Arrays.asList(Arrays.asList(1,2,3), Arrays.asList(4,5,6));
Why so defensive?
– shmosel
Nov 13 '18 at 21:37
@shmosel what do you mean?
– Liad Saubron
Nov 13 '18 at 21:39
2
Why do you need to copy it to anew ArrayList?
– shmosel
Nov 13 '18 at 21:42
edited, thanks! @shmosel
– Liad Saubron
Nov 14 '18 at 8:09
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
List<List<Integer>> list = Arrays.asList(Arrays.asList(1,2), Arrays.asList(3,4));
In Java 9+ you can replace Arrays.asList() with List.of().
add a comment |
List<List<Integer>> list = Arrays.asList(Arrays.asList(1,2), Arrays.asList(3,4));
In Java 9+ you can replace Arrays.asList() with List.of().
add a comment |
List<List<Integer>> list = Arrays.asList(Arrays.asList(1,2), Arrays.asList(3,4));
In Java 9+ you can replace Arrays.asList() with List.of().
List<List<Integer>> list = Arrays.asList(Arrays.asList(1,2), Arrays.asList(3,4));
In Java 9+ you can replace Arrays.asList() with List.of().
edited Nov 13 '18 at 22:15
shmosel
36.3k43994
36.3k43994
answered Nov 13 '18 at 22:03
MaltMalt
16.8k34163
16.8k34163
add a comment |
add a comment |
List<List<Integer>> list =
Arrays.asList(Arrays.asList(1,2,3), Arrays.asList(4,5,6));
Why so defensive?
– shmosel
Nov 13 '18 at 21:37
@shmosel what do you mean?
– Liad Saubron
Nov 13 '18 at 21:39
2
Why do you need to copy it to anew ArrayList?
– shmosel
Nov 13 '18 at 21:42
edited, thanks! @shmosel
– Liad Saubron
Nov 14 '18 at 8:09
add a comment |
List<List<Integer>> list =
Arrays.asList(Arrays.asList(1,2,3), Arrays.asList(4,5,6));
Why so defensive?
– shmosel
Nov 13 '18 at 21:37
@shmosel what do you mean?
– Liad Saubron
Nov 13 '18 at 21:39
2
Why do you need to copy it to anew ArrayList?
– shmosel
Nov 13 '18 at 21:42
edited, thanks! @shmosel
– Liad Saubron
Nov 14 '18 at 8:09
add a comment |
List<List<Integer>> list =
Arrays.asList(Arrays.asList(1,2,3), Arrays.asList(4,5,6));
List<List<Integer>> list =
Arrays.asList(Arrays.asList(1,2,3), Arrays.asList(4,5,6));
edited Nov 14 '18 at 8:09
answered Nov 13 '18 at 21:29
Liad SaubronLiad Saubron
794
794
Why so defensive?
– shmosel
Nov 13 '18 at 21:37
@shmosel what do you mean?
– Liad Saubron
Nov 13 '18 at 21:39
2
Why do you need to copy it to anew ArrayList?
– shmosel
Nov 13 '18 at 21:42
edited, thanks! @shmosel
– Liad Saubron
Nov 14 '18 at 8:09
add a comment |
Why so defensive?
– shmosel
Nov 13 '18 at 21:37
@shmosel what do you mean?
– Liad Saubron
Nov 13 '18 at 21:39
2
Why do you need to copy it to anew ArrayList?
– shmosel
Nov 13 '18 at 21:42
edited, thanks! @shmosel
– Liad Saubron
Nov 14 '18 at 8:09
Why so defensive?
– shmosel
Nov 13 '18 at 21:37
Why so defensive?
– shmosel
Nov 13 '18 at 21:37
@shmosel what do you mean?
– Liad Saubron
Nov 13 '18 at 21:39
@shmosel what do you mean?
– Liad Saubron
Nov 13 '18 at 21:39
2
2
Why do you need to copy it to a
new ArrayList?– shmosel
Nov 13 '18 at 21:42
Why do you need to copy it to a
new ArrayList?– shmosel
Nov 13 '18 at 21:42
edited, thanks! @shmosel
– Liad Saubron
Nov 14 '18 at 8:09
edited, thanks! @shmosel
– Liad Saubron
Nov 14 '18 at 8:09
add a comment |
There's a very complete answer over here already: stackoverflow.com/a/47288158/236528
– mjuarez
Nov 13 '18 at 21:26
2
What do you want to initialise it to?
– khelwood
Nov 13 '18 at 21:29