Here is the FizzBuzz Solution in java 8 with different methods,
Here is the Before Java 8, simple solution:
public static void main(String[] args){
for(int i= 1; i <= 20; i++){
if(i % 15 == 0){
System.out.println("FizzBuzz");
}else if(i % 3 == 0){
System.out.println("Fizz");
...
Print all the names of student in alphabetical order by gender in java 8 using Stream API
This question is some tricky, you have to create enum and student class then sorted the predefined condition in question.
Enum of Gender
public enum Gender {
MALE,FEMALE;
}
Person Class with getter , setter and override to string method.
public class Person {
public Gender getGender() {
return...
Print multiple of 3 up to 30 in java 8 using Stream API
Display the multiple of any number in java 8 using stream API, Here is the example of multiple of 3 up to 30 and print them.
IntStream.iterate(1, i->i+1).map(i->i*3).limit(100).forEach(System.out::println);
Output:
3
6
9
12
15
18
21
24
27
30
Happy Coding ...
Combine different list in to Set(single list) in Java 8 using Stream API
Combine the different list in to single list in java, there should be used in java 8 Creating a stream pipeline that transforms a list of sets (of type String) into the union of those
sets. Make use of the reduce method for streams.
Example:
Orginal list [{“A”, “B”}, {“D”}, {“1”, “3”, “5”}] to the
Final...
Sub List or partition list according to index in java 8 using Stream API
Question is like this, Create a method Stream<String> streamSection(Stream<String> stream, int m, int n) which extracts a substream from the input stream stream consisting of all elements from position m to position n , inclusive; you must use only Stream operations to do this. You can assume...
Print Square in Java Using Lambda or Stream API
Creates an IntStream using the iterate method. The method prints to the console the
first num squares. For instance, if num = 4, then your method would output 1, 4, 9, 16. Note:
You will need to come up with a function to be used in the second argument of iterate .
public class Test {
public static...