Use Predicate and BiPredicate in Lambda Expression in Java

raja
Updated on 13-Jul-2020 07:18:22

2K+ Views

A Predicate interface defined in java.util.function package. It represents a boolean-valued function with one argument. It is kind of a functional interface whose functional method is the test(). BiPredicate interface is similar to the Predicate interface with two arguments. It can be used as an assignment target for a lambda expression.Syntax for Predicate@FunctionalInterface public interface PredicateExampleimport java.util.*; import java.util.function.*; import java.util.stream.*; public class EmployeePredicateTest {    public static void main(String[] args) {       Employee e1 = new Employee(1, 23, "M", "Raja");       Employee e2 = new Employee(2, 13, "M", "Jai");       Employee e3 = new Employee(3, 36, "F", "Yamini");       ... Read More

Symmetric Min-Max Heaps

Arnab Chakraborty
Updated on 13-Jul-2020 07:15:03

2K+ Views

A symmetric min-max heap (SMMH) is defined as a complete binary tree in which each node except the root has exactly one element. The root of an SMMH be empty and the total number of nodes in the SMMH is m + 1, where m is the number of elements.Let y be any node of the SMMH. Let elements(y) be the elements in the sub tree rooted at y but excluding the element (if any) in y. Assume that elements(y) j= ∅. y satisfies the following properties:The left child of y has the minimum element in elements(y).The right child of ... Read More

Sort a List by Name Using Comparator Interface in Java

raja
Updated on 13-Jul-2020 07:00:37

847 Views

Comparator interface can be used to order the objects of user-defined classes. It is capable of comparing two objects of two different classes. We can sort a list of objects where we can't modify the object’s source code to implement Comparable interface. A lambda expression can't be executed on its own and used to implement methods that are declared in a functional interface.In the below example, we need to sort a list by name using the Comparator interface and Stream API with the help of lambda expressions.Exampleimport java.util.*; import java.util.function.*; import java.util.stream.*; public class ListSortByNameTest {    public static void main(String[] args) {       List arrayList = new ArrayList(); ... Read More

Use Function and BiFunction Interfaces in Lambda Expression in Java

raja
Updated on 13-Jul-2020 06:37:00

2K+ Views

The Function interface is a pre-defined functional interface that can be used as an assignment target for a lambda expression or method reference. It takes a single parameter and returns result by calling the apply() method. While the BiFunction interface is also a pre-defined functional interface that takes two parameters and returns a result. It is similar to the Function interface except it takes two parameters.Syntax@FunctionalInterface public interface Function @FunctionalInterface public interface BiFunctionExampleimport java.util.function.BiFunction; import java.util.function.Function; public class SampleFunctionBiFunctionTest {    public static void main(String[] args) {       Function printNumber = a -> a*10;       System.out.println("The number is: "+ printNumber.apply(10));   ... Read More

Use Consumer and BiConsumer Interfaces in Lambda Expression in Java

raja
Updated on 13-Jul-2020 06:30:59

4K+ Views

A Consumer interface is a predefined functional interface that can be used when creating lambda expressions or method references. This interface represents an operation that accepts a single input parameter and doesn't return anything. It contains only one method named accept(). The BiConsumer interface is similar to a Consumer interface and accepts two input parameters and doesn’t return anything.Syntax@FunctionalInterface public interface Consumer @FunctionalInterface public interface BiConsumerExampleimport java.util.*; import java.util.function.*; public class ConsumerBiConsumerTest {    public static void main(String[] args) {       Consumer c = (x) -> System.out.println(x.toLowerCase());  // lambda expression       c.accept("Raja");         Consumer con = (x) -> {  // ... Read More

Spanning Tree Protocol

Moumita
Updated on 13-Jul-2020 05:50:38

6K+ Views

Spanning Tree Protocol (STP) is a communication protocol operating at data link layer the OSI model to prevent bridge loops and the resulting broadcast storms. It creates a loop − free topology for Ethernet networks.Working PrincipleA bridge loop is created when there are more than one paths between two nodes in a given network. When a message is sent, particularly when a broadcast is done, the bridges repeatedly rebroadcast the same message flooding the network. Since a data link layer frame does not have a time-to-live field in the header, the broadcast frame may loop forever, thus swamping the channels.Spanning ... Read More

What is Wormhole Switching

Moumita
Updated on 13-Jul-2020 05:48:37

1K+ Views

In data communications, wormhole switching a flow control technique where large data frames or packets are partitioned and then transmitted. When a switching device (a bridge or a switch) receives a data packet, it partitions the packet into small parts called flow control units or flits. The flits are transmitted one by one instead of the whole packet. Also called wormhole flow control, wormhole switching is subtype of flit-buffer flow control methods and is based upon fixed links.Working PrincipleIn this technique, each packet or frame is broken into smaller pieces of data called flits. The header flits contain the destination ... Read More

What is Cut-Through Switching?

Moumita
Updated on 13-Jul-2020 05:48:03

835 Views

In data communications, cut-through switching is a method of switching data frame or data packets, where the switching device (bridge or switch) forwards the frames or packets as soon as the destination address is available without waiting for the rest of the data to arrive.Working PrincipleCut-through switching is used in packet switching systems. In packet-switching, the message is divided into a number of units called packets that are individually routed from the source to the destination. There is no need to establish a dedicated circuit for communication, since it is a connectionless network switching technique.In cut − through switching, when ... Read More

Uses of Bridges in Computer Network

Moumita
Updated on 13-Jul-2020 05:47:03

10K+ Views

A bridge is a network device that connects multiple LANs (local area networks) together to form a larger LAN. The process of aggregating networks is called network bridging. A bridge connects the different components so that they appear as parts of a single network. Bridges operate at the data link layer of the OSI model and hence also referred as Layer 2 switches.The following diagram shows a bridges connecting two LANs −Uses of BridgeBridges connects two or more different LANs that has a similar protocol and provides communication between the devices (nodes) in them.By joining multiple LANs, bridges help in ... Read More

What is Virtual LAN

Moumita
Updated on 13-Jul-2020 05:44:51

16K+ Views

Virtual Local Area Networks or Virtual LANs (VLANs) are a logical group of computers that appear to be on the same LAN irrespective of the configuration of the underlying physical network. Network administrators partition the networks to match the functional requirements of the VLANs so that each VLAN comprise of a subset of ports on a single or multiple switches or bridges. This allows computers and devices in a VLAN to communicate in the simulated environment as if it is a separate LAN.Features of VLANsA VLAN forms sub-network grouping together devices on separate physical LANs.VLAN's help the network manager to ... Read More

Advertisements