How can I create a stream from an array?

后端 未结 6 2292
挽巷
挽巷 2020-11-27 03:18

Currently whenever I need to create stream from an array, I do

String[] array = {\"x1\", \"x2\"};
Arrays.asList(array).stream();

Is there s

6条回答
  •  臣服心动
    2020-11-27 04:18

    rarely seen, but this is the directest way

    Stream.Builder builder = Stream.builder();
    for( int i = 0; i < array.length; i++ )
      builder.add( array[i] );
    Stream stream = builder.build();
    

提交回复
热议问题