java - IntStream strange error -
java 8 has new interface, named intstream
. used of()
static method , encountered strange error:
this static method of interface
intstream
can accessedintstream.of
but can see in following code, i, exactly, used intstream.of
import java.util.stream.intstream; public class test { public static void main(string[] args) { int[] listofnumbers = {5,4,13,7,7,8,9,10,5,92,11,3,4,2,1}; system.out.println(intstream.of(listofnumbers).sum()); } }
moreover, if check api, see method has been declared in similar way used.
although intstream.of(int...) seems work more expected use arrays.stream(int[]).
public void test() { int[] listofnumbers = {5, 4, 13, 7, 7, 8, 9, 10, 5, 92, 11, 3, 4, 2, 1}; // works fine designed ints instead of int[]s. system.out.println(intstream.of(listofnumbers).sum()); // expected use. system.out.println(intstream.of(5, 4, 13, 7, 7, 8, 9, 10, 5, 92, 11, 3, 4, 2, 1).sum()); // better approach int[]. system.out.println(arrays.stream(listofnumbers).sum()); }
Comments
Post a Comment