• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java8 - Streams - Convert multidiamentional array to list  RSS feed

 
Ranch Hand
Posts: 95
1
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anybody tell me, how I can convert multidiamentional to list?
E.g. - I have an array like this:

I want to convert it into list.


Atul
 
Atul More
Ranch Hand
Posts: 95
1
Java jQuery Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There are ways to do that, I found one of them:

 
author & internet detective
Marshal
Posts: 38152
617
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a cow for answering your own question so quickly!
 
Atul More
Ranch Hand
Posts: 95
1
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne,

No, I was in between the steps when I asked the question and was able to solved immediately after.
So update the answer. Nothing else.
 
Marshal
Posts: 58830
179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your post has proven useful to somebody else
You said you wanted to convert the array to a List, but there are two possible interpretations of that statement. One would create a List<int[]> and the other a List<List<Integer>>. You obviously wanted the second type of List.
 
Greenhorn
Posts: 1
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another solution may be a customized collector like this:
 
Bartender
Posts: 2156
46
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another solution using flatMap....or if you think Stream.of reads better:
 
Saloon Keeper
Posts: 8766
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My personal favorite would be a small tweak to Paweł's first version:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!