A lambda expression is a function that expects and accepts input parameters and produces output results. It is an instance of a functional interface and also known as a single abstract method interface (SAM interface) like Runnable, Comparator, Callable and etc. We can declare a variable as a final string[] array and able to access that array index within a lambda expression.Exampleimport java.util.*; public class LambdaTest { public static void main(String args[]) { final String[] country = {null}; List cities = new ArrayList(); cities.add("Hyderabad"); cities.add("Ireland"); cities.add("Texas"); ... Read More
ToLongBiFunction is a in-built functional interface from java.util.function package. This functional interface accepts two reference type parameters as input and produces a long-valued result. ToLongBiFunction interface can be used as an assignment target for a lambda expression or method reference and contains only one abstract method: applyAsLong().Syntax@FunctionalInterface interface ToLongBiFunction { long applyAsLong(T t, U u); }Exampleimport java.util.*; import java.util.function.ToLongBiFunction; public class ToLongBiFunctionTest { public static void main(String[] args) { ToLongBiFunction getMobileNum = (map, value) -> { // lambda if(map != null && !map.isEmpty()) { if(map.containsKey(value)) { ... Read More
ToLongFunction is a functional interface defined in java.util.function package. This functional interface accepts a reference type as input and produces a long-valued result. ToLongFunction interface can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsLong().Syntax@FunctionalInterface interface ToLongFunction { long applyAsLong(T value); }Exampleimport java.util.*; import java.util.function.ToLongFunction; public class ToLongFunctionTest { public static void main(String args[]) { List list = new ArrayList(); list.add("11"); list.add("22"); list.add("33"); list.add("44"); list.add("55"); ToLongFunction function = (String item) -> Long.valueOf(item); // ... Read More
ToIntBiFunction is a built-in functional interface from java.util.function package. This interface accepts two parameters as input and produces an int-valued result. ToIntBiFunction interface can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsInt() and doesn't contain any default or static methods.Syntax@FunctionalInterface interface ToIntBiFunction { int applyAsInt(T t, U u); }Exampleimport java.util.function.ToIntBiFunction; public class ToIntBiFunctionTest { public static void main(String args[]) { ToIntBiFunction test = (t, u) -> t * u; System.out.println("The multiplication of t and u is: " + test.applyAsInt(10, 7)); System.out.println("The multiplication of t and u is: " ... Read More
ToDoubleBiFunction is a functional interface defined in java.util.function package. This functional interface accepts two parameters as input and produces a double-valued result. ToDoubleBiFunction interface can be used as an assignment target for a lambda expression or method reference. This interface contains only one abstract method: applyAsDouble() and doesn't contain any default or static methods.Syntax@FunctionalInterface interface ToDoubleBiFunction { double applyAsDouble(T t, U u); }Exampleimport java.util.function.ToDoubleBiFunction; public class ToDoubleBiFunctionTest { public static void main(String args[]) { ToDoubleBiFunction test = (t, u) -> t / u; // lambda expression System.out.println("The division of t and u is: " + test.applyAsDouble(50, ... Read More
A Map interface implements the Collection interface that provides the functionality of the map data structure. A Map doesn't contain any duplicate keys and each key is associated with a single value. We can able to access and modify values using the keys associated with them.In the below two examples, we can able to sort a Map by both key and value with the help of lambda expression.Example for sorting of Map using Keyimport java.util.*; import java.util.stream.*; public class MapSortUsingKeyTest { public static void main(String args[]) { // Sort a Map by their key Map map = new HashMap(); ... Read More
LongUnaryOperator is a functional interface from java.util.function package. This functional interface accepts a single long-valued operand and produces a long-valued result. LongUnaryOperator interface can be used as an assignment target for lambda expression and method reference. It contains one abstract method: applyAsLong(), one static method: identity() and two default methods: andThen() and compose().Syntax@FunctionalInterface public interface LongUnaryOperator long applyAsLong(long operand); }Exampleimport java.util.function.LongUnaryOperator; public class LongUnaryOperatorTest { public static void main(String args[]) { LongUnaryOperator getSquare = longValue -> { // lambda long result = longValue * longValue; System.out.println("Getting square: " + result); ... Read More
Do you see your devices connected to your Wifi-network, but presently are you are facing problem recollecting your Wifi password, which you have previously used and connected all your devices with your Wifi network.The reason as to why you may have forgotten your Wifi password is, you would have clicked on the box, which states remember the password. This helps you escape the pain of entering your password every time when you login to your device. Days would have passed and you might not remember what password you have kept for your Wifi-Network. Another reason, as to why many people ... Read More
Your smartphone is your personal device which stores many of your personal files and data. There may be several reasons you would want to hide your data which includes private photos, videos and messages. If you want to hide a file from prying eyes on your smartphone, then it’s incredibly important that you can learn some methods for hiding files or folders so that you can properly store and sort files as needed.There are ways you can hide files on your phone with ease. Some of these methods don’t need any apps while some of them include various apps which ... Read More
To change the background color of the font, you can use the GUI and command line both.With GUI − Colors → Screen Background.CLI −$host.UI.RawUI.BackgroundColor = "DarkBlue"You will notice that the background color of the text has been changed to DarkBlue.