Java 8 :: Streams and Lambda Expressions
/*
* Problem No: #3
* Problem Definition: How to print Integer Array Using Arrays.stream()?
*
* Answer: By Using,
* > java.util.Arrays: This class contains various methods for manipulating arrays (such as sorting and searching). This class also contains a static factory that allows arrays to be viewed as lists.
*
*> IntStream java.util.Arrays.stream(int[] array): Returns a sequential IntStream with the specified array as its source. **array - the array, assumed to be unmodified during use.
*
*> java.util.stream.Stream.forEach(): Performs an act ion for each element of this stream.
*
* Program By: Mr.DIpak SOnar
* Date : 23rd Oct 2016
*/
import java.util.Arrays;
public class StreamWithIntArrayEx {
public static void main(String[] args) {
int[] intArray = new int[7];
intArray[0] = 11;
intArray[1] = 22;
intArray[2] = 33;
intArray[3] = 44;
intArray[4] = 55;
intArray[5] = 66;
intArray[6] = 77;
System.out.println("Printing Integer Array Using Arrays.stream(): ");
Arrays.stream(intArray).forEach(System.out::println);
}
}
/*
* Problem No: #3
* Problem Definition: How to print Integer Array Using Arrays.stream()?
*
* Answer: By Using,
* > java.util.Arrays: This class contains various methods for manipulating arrays (such as sorting and searching). This class also contains a static factory that allows arrays to be viewed as lists.
*
*> IntStream java.util.Arrays.stream(int[] array): Returns a sequential IntStream with the specified array as its source. **array - the array, assumed to be unmodified during use.
*
*> java.util.stream.Stream.forEach(): Performs an act ion for each element of this stream.
*
* Program By: Mr.DIpak SOnar
* Date : 23rd Oct 2016
*/
import java.util.Arrays;
public class StreamWithIntArrayEx {
public static void main(String[] args) {
int[] intArray = new int[7];
intArray[0] = 11;
intArray[1] = 22;
intArray[2] = 33;
intArray[3] = 44;
intArray[4] = 55;
intArray[5] = 66;
intArray[6] = 77;
System.out.println("Printing Integer Array Using Arrays.stream(): ");
Arrays.stream(intArray).forEach(System.out::println);
}
}
No comments:
Post a Comment