// We can use Stream.of() to create a stream from similar type of data.
// For example, we can create Stream of integers from a group of int or
// Integer objects.
Stream<Integer> stream = Stream.of(1, 2, 3, 4);
// works fine
stream = Stream.of(new Integer[] { 1, 2, 3, 4 });
// Compile time error, Type mismatch: cannot convert from Stream<int[]>
// to Stream<Integer>
// stream1 = Stream.of(new int[]{1,2,3,4});
Future:
ExecutorService pool = Executors.newFixedThreadPool(3);
Future<String> futureTask = getValue("1", "2");
System.out.println("future done? " + futureTask.isDone()); //task may not be done at this stage
String result2 = futureTask.get(); //wait till the task is done
System.out.println("future done? " + futureTask.isDone());
System.out.print("result: " + result2);
public Future<String> getValue(String value1, String value2) {
return pool.submit(new Callable<String>() {
@Override
public String call() throws Exception {
Thread.sleep(3000);
return value1+value2;
}
});
}