[Question] How to effectively convert a list of list of lists of string into an array of arrays of arrays of string in Java>8

Ethan McCue ethan at mccue.dev
Mon May 30 22:04:19 UTC 2022


static String[][][] convert(List<List<List<String>>> items) {
    return items.stream().map(__ -> __.stream().map(___ ->
___.toArray(String[]::new)).toArray(String[][]::new)).toArray(String[][][]::new);
}


On Mon, May 30, 2022 at 5:45 PM Remi Forax <forax at univ-mlv.fr> wrote:

> Hi Sam, wrong list,
> openjdk.org is about people implementing the JDK, it's not a helping
> forum about how to do funny things in Java.
>
> Stackoverflow.com is a better web site for the kind of questions you are
> asking.
>
> reards,
> Rémi
>
>   public static List<List<List<String>>> wrap(String[][][] array) {
>     return new AbstractList<>() {
>       @Override
>       public List<List<String>> get(int index) {
>         var item = array[index];
>         return new AbstractList<>() {
>           @Override
>           public List<String> get(int index) {
>             var item2 = item[index];
>             return new AbstractList<>() {
>               @Override
>               public String get(int index) {
>                 return item2[index];
>               }
>
>               @Override
>               public int size() {
>                 return item2.length;
>               }
>             };
>           }
>
>           @Override
>           public int size() {
>             return item.length;
>           }
>         };
>       }
>
>       @Override
>       public int size() {
>         return array.length;
>       }
>     };
>   }
>
>
>
> ----- Original Message -----
> > From: "sam smith" <qustacksm2123456 at gmail.com>
> > To: "discuss" <discuss at openjdk.java.net>
> > Sent: Monday, May 30, 2022 11:14:52 PM
> > Subject: [Question] How to effectively convert a list of list of lists
> of string into an array of arrays of arrays of
> > string in Java>8
>
> > Hello guys,
> >
> > Let's say i have a List<List<List<String>>> that i want to convert into a
> > String[][][]; how to do that effectively in Java versions greater that 8?
> >
> > Thanks.
>


More information about the discuss mailing list