• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Java8 - Streams - Convert multidiamentional array to list  RSS feed

 
Ranch Hand
Posts: 113
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: 113
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: 38508
653
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: 113
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: 59769
188
  • 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: 2180
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: 9138
172
  • 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!