Found 4332 Articles for Java 8

DoubleStream flatMap() method in Java

Chandu yadav
Updated on 30-Jul-2019 22:30:25

88 Views

The flatMap() method of the DoubleStream class returns a stream with the results of replacing each element of this stream with the contents of a mapped stream formed by applying the provided mapping function to each element.The syntax is as followsDoubleStream flatMap(DoubleFunction

DoubleStream findFirst() method in Java

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

64 Views

The findFirst() method returns an OptionalDouble describing the first element of this stream. It returns an empty OptionalDouble if the stream is empty.The syntax is as followsOptionalDouble findFirst()Here, OptionalDouble is a container object which may or may not contain a double value.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;First, create a DoubleStream with some elementsDoubleStream doubleStream = DoubleStream.of(15.6, 30.2, 50.5, 78.9, 80.4, 95.8);Now, get the first element of this stream using the findFirst() methodOptionalDouble res = doubleStream.findFirst();The following is an example to implement DoubleStream findFirst() method in JavaExample Live Demoimport java.util.*; import java.util.stream.DoubleStream; public class Demo { ... Read More

Create LabelValue Tuple using with() method in Java

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

64 Views

You can create a LabelValue tuple using with() method as well. The parameter of the with() method is the label and value of the LabelValue class.Let us first see what we need to work with JavaTuples. To work with LabelValue class in JavaTuples, you need to import the following packageimport org.javatuples.LabelValue;Note Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuplesSteps − How to ... Read More

Create Decade Tuple from another collection in Java

George John
Updated on 30-Jul-2019 22:30:25

63 Views

To create Decade Tuple from another collection in Java, use the fromArray() or the fromCollection() method. Here, we will see how to create a Decade Tuple using the fromCollection() method. This method will allow us to crate a Decade Tuple from a List collection in Java.Let us first see what we need to work with JavaTuples. To work with Decade class in JavaTuples, you need to import the following packageimport org.javatuples.Decade;Note Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then RightClick Project -> Properties -> Java Build Path -> Add External Jars and upload ... Read More

How to add elements in Java CopyOnWriteArrayList?

Chandu yadav
Updated on 30-Jul-2019 22:30:25

109 Views

To add elements in CopyOnWriteArrayList class in Java, use the add() method. Here, the element is appended to the end of the list.The syntax is as followsboolean add(E e)Here, the parameter e is the element to be appended to this list.To work with CopyOnWriteArrayList class, you need to import the following packageimport java.util.concurrent.CopyOnWriteArrayList;The following is an example to add elements in the CopyOnWriteArrayList class in JavaExample Live Demoimport java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] args) {       CopyOnWriteArrayList       arrList = new CopyOnWriteArrayList();       arrList.add(100);       arrList.add(250);     ... Read More

The clear() method of AbstractList class in Java

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

79 Views

Remove all the elements from the list using the clear() method of the AbstractList class. After using the method, the list won’t be having any elements.The syntax is as followspublic void clear()To work with the AbstractList class, import the following packageimport java.util.AbstractList;The following is an example to implement clear() method of the AbstractlList class in JavaExample Live Demoimport java.util.ArrayList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList       myList = new ArrayList();       myList.add(75);       myList.add(100);       myList.add(150);       myList.add(200);     ... Read More

The equals() method of AbstractList class in Java

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

131 Views

The equals() method of the AbstractList class is used to compare the specified object with this list for equality. The value TRUE is returned if both the lists are same i.e the same size and elements.The syntax is as followspublic boolean equals(Object ob)Here, ob is the object is to be compared for equality. To work with the AbstractList class, import the following packageimport java.util.AbstractList;The following is an example to implement equals() method of the AbstractlList class in JavaExample Live Demoimport java.util.ArrayList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList = new ... Read More

DoubleStream limit() method in Java

George John
Updated on 30-Jul-2019 22:30:25

51 Views

The limit() method of the DoubleStream class returns a stream consisting of the elements of this stream, truncated to be no longer than max in length. The max is a parameter of the limit() method.The syntax is as followsDoubleStream limit(long max)Here, max is the number of elements the stream should be limited to.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;Create a DoubleStream and add elementsDoubleStream doubleStream = DoubleStream.of(10.8, 20.7, 25.8, 35.7, 78.2, 89.7, 67.8, 86.3);Now, to display n number of elements, set it as a parameter value for limit()doubleStream.limit(5)The following is an example to implement DoubleStream ... Read More

DoubleStream mapToInt() method in Java

Chandu yadav
Updated on 30-Jul-2019 22:30:25

104 Views

The mapToInt() function of the DoubleStream class returns an IntStream consisting of the results of applying the given function to the elements of this stream.The syntax is as followsIntStream mapToInt(DoubleToIntFunction mapper)Here, mapper is a stateless function to apply to each element. The DoubleToIntFunction is a function that accepts a double-valued argument and produces an int-valued result.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream mapToInt() method in JavaExample Live Demoimport java.util.stream.IntStream; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream doubleStream = DoubleStream.of(45.8, ... Read More

IntStream iterator() method in Java

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

179 Views

The iterator() method of the IntStream class in Java is used to return an iterator for the elements of this stream.The syntax is as followsPrimitiveIterator.OfInt iterator()Here, PrimitiveIterator.OfInt is an Iterator specialized for int values. To work with the IntStream class in Java, import the following packageimport java.util.stream.IntStream;Create an IntStream and add some elementsIntStream intStream = IntStream.of(15, 40, 55, 70, 95, 120);To return an iterator for the stream elementsPrimitiveIterator.OfInt primIterator = intStream.iterator();The following is an example to implement IntStream iterator() method in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       ... Read More

Advertisements