This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IfPresentExample { | |
public static void main(String[] args) { | |
List<Integer> numbers = Arrays.asList(10, 20, 30, 40, 50, 60, 70, 80, 90); | |
Optional<Integer> first = numbers.stream().filter(a -> a > 500).findFirst(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IfPresentOrElseExample { | |
public static void main(String[] args) { | |
List<Integer> numbers = Arrays.asList(10, 20, 30, 40, 50, 60, 70, 80, 90); | |
Optional<Integer> first = numbers.stream().filter(a -> a > 500).findFirst(); | |
if (first.isPresent()) { | |
System.out.println(first.get()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pack1; | |
public class Demo1 | |
{ | |
public void test() | |
{ | |
System.out.println("pack1.test"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pack2; | |
import pack1.Demo1; | |
public class Demo2 { | |
public void test2() | |
{ | |
System.out.println("pack2.Demo2 method"); | |
Demo1 obj = new Demo1(); | |
obj.test(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pack2.Demo2; | |
class Test { | |
public static void main(String[] args) { | |
System.out.println("Test class main"); | |
Demo2 obj = new Demo2(); | |
obj.test2(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class User(id: Int, name: String) | |
case class Tweet(id: Int, content: String) | |
object Test extends App{ | |
val user = User(1, "Kunal") | |
val tweet = Tweet(11, "Scala Rocks") | |
println(s"User ID :- ${user.id}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class UserId(id: Int) | |
case class Username(name: String) | |
case class TweetId(id: Int) | |
case class TweetContent(content: String) | |
case class User(id: UserId, name: Username) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class UserId(id: Int) extends AnyVal | |
case class Username(name: String) extends AnyVal | |
case class TweetId(id: Int) extends AnyVal | |
case class TweetContent(content: String) extends AnyVal | |
case class User(id: UserId, name: Username) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.knoldus; | |
import java.util.ArrayList; | |
import java.util.stream.Collectors; | |
public class LambdaEx { | |
public static void main(String[] args) { | |
ArrayList<String> list1 = null; | |
list1.stream().map(elem -> elem + "Knoldus").collect(Collectors.toList()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.knoldus; | |
import org.apache.commons.collections4.CollectionUtils; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
public class LambdaEx { |