to 2D Array by Stream Collectors - Java Collection Framework

Java examples for Collection Framework:Array Dimension

Description

to 2D Array by Stream Collectors

Demo Code


//package com.java2s;
import java.util.Collection;

import java.util.stream.Collectors;

import java.util.stream.Stream;

public class Main {
    public static void main(String[] argv) throws Exception {
        Collection collection = java.util.Arrays.asList("asdf",
                "java2s.com");
        System.out/*from   www.  j  a v  a  2s . com*/
                .println(java.util.Arrays.toString(to2DArray(collection)));
    }

    public static double[][] to2DArray(Collection<double[]> collection) {
        return collection.toArray(new double[collection.size()][]);
    }

    public static double[][] to2DArray(Stream<double[]> stream) {
        return to2DArray(stream.collect(Collectors.toList()));
    }
}

Related Tutorials