Skip to content

Instantly share code, notes, and snippets.

@ariesmcrae
Last active February 22, 2019 02:21
Show Gist options
  • Select an option

  • Save ariesmcrae/53da8281eba314de15159552a1efe949 to your computer and use it in GitHub Desktop.

Select an option

Save ariesmcrae/53da8281eba314de15159552a1efe949 to your computer and use it in GitHub Desktop.
Arrays.asList vs Stream.Of
package com.ariesmcrae.streams;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
public class MainBuldingStreams {
public static void main(String[] args) {
// first way
List<Integer> ints = Arrays.asList(0, 1, 2, 3, 4);
Stream<Integer> stream = ints.stream();
stream.forEach(System.out::print);
System.out.println("\n");
// second way
stream = Stream.of(0, 1, 2, 3, 4, 5);
stream.forEach(System.out::print);
}
/*
01234
012345
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment