• 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Java8 - Streams - Convert multidiamentional array to list  RSS feed

 
Ranch Hand
Posts: 118
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: 118
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
Posts: 38906
684
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: 118
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: 61689
192
  • 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: 2200
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:
 
Bartender
Posts: 9486
184
  • 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:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!