Found 4332 Articles for Java 8

The lastIndexOf() method of AbstractList class in Java

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

64 Views

The lastIndexOf() method of the AbstractList return the index of the last occurrence of an element in the list. If the element does not exist in the list, then -1 is returned.The syntax is as followspublic int lastIndexOf(Object ob)Here, the parameter ob is the element to be searched. To work with the AbstractList class, import the following packageimport java.util.AbstractList;The following is an example to implement lastIndexOf() 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); ... Read More

IntStream skip() method in Java

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

221 Views

The skip() method of the IntStream class in Java returns a stream consisting of the remaining elements of this stream after discarding the first n elements of the stream.The syntax is as followsIntStream skip(long n)Here, n is the number of elements to skip. The method returns the new stream.Create an IntStream and add some elements within a range using range() methodIntStream intStream = IntStream.range(20, 40);Now to skip some elements and only display the rest of them, use the skip() methodintStream.skip(15)The following is an example to implement IntStream skip() method in Java. It skips 15 elements since we have set the ... Read More

IntStream generate() method in Java

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

381 Views

The generate() method in the IntStream class returns an infinite sequential unordered stream where each element is generated by the provided IntSupplier.The syntax is as followsstatic IntStream generate(IntSupplier i)Here, i is the IntSupplier for generated elements. The IntSupplier represents a supplier of int-valued results.The following is an example to implement IntStream generate() method in Java. We have used the limit() method here as well to limit the number of elements we want from the streamExample Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream intStream = IntStream.generate(()       ... Read More

IntStream allMatch() method in Java

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

479 Views

The allMatch() method of the IntStream class in Java returns whether all elements of this stream match the provided predicate.The syntax is as followsboolean allMatch(IntPredicate predicate)Here, the predicate parameter is a stateless predicate to apply to elements of this stream. The IntPredicate represents a predicate of one int-valued argument.The allMatch() method returns true if either all elements of the stream match the provided predicate or the stream is empty.The following is an example to implement IntStream allMatch() method in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo { public static void main(String[] args) { ... Read More

Search for a value in Java KeyValue Tuple

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

69 Views

To search for a value in KeyValue Tuple, use the contains() method. Here, the value to be searched should be set as the parameter of the method. The return value is a boolean i.e. TRUE, if the value exists, else FALSE. Let us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following packageimport org.javatuples.KeyValue;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 ... Read More

Set value in the JavaTuples KeyValue class

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

77 Views

To set value in the JavaTuples KeyValue class, you need to use the setValue() method. Let us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following packageimport org.javatuples.KeyValue;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 run JavaTuples program in EclipseThe following is an example to set ... Read More

IntStream anyMatch() method in Java

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

479 Views

The anyMatch() method in the IntStream class in Java returns whether any elements of this stream match the provided predicate.The syntax is as followsboolean anyMatch(IntPredicate predicate)To work with the IntStream class in Java, import the following packageimport java.util.stream.IntStream;Here, the predicate parameter is a stateless predicate to apply to elements of this stream.Create an IntStream and add some elementsIntStream intStream = IntStream.of(20, 40, 60, 80, 100);Now, use the anyMatch() method to set for a condition. If any of the element match with the condition, TRUE is returnedboolean res = intStream.anyMatch(a -> a < 50); The following is an example to implement ... Read More

The toArray() method of AbstractSequentialList in Java

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

57 Views

The toArray() method is inherited from the AbstractCollection() method. It returns an array containing similar elements in this collection.The syntax is as followspublic Object[] toArray()To work with the AbstractSequentialList class in Java, you need to import the following packageimport java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList toArray() method in JavaExample Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo {    public static void main(String[] args) {       AbstractSequentialList absSequential = new LinkedList();       absSequential.add(210);       absSequential.add(290);       absSequential.add(350);       absSequential.add(490);       absSequential.add(540);       absSequential.add(670);     ... Read More

IntStream forEach() method in Java

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

356 Views

The forEach() method is used in Java to perform an action for each element of this stream. Display the stream using the forEach() method in Java IntStreamThe syntax is as followsvoid forEach(IntConsumer action)Here, action is a non-interfering action to perform on the elements.Create IntStream and add elementsIntStream intStream = IntStream.of(15, 30, 40, 60, 75, 90);Now, display the streamintStream.forEach(System.out::println);The following is an example to implement IntStream forEach() method in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream intStream = IntStream.of(15, 30, 40, 60, 75, 90);       intStream.forEach(System.out::println); ... Read More

IntStream noneMatch() method in Java

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

630 Views

The noneMatch() method in Java returns whether no elements of this stream match the provided predicate. The true boolean value is returned if either no elements of the stream match the provided predicate or the stream is empty.The syntax is as followsBoolean noneMatch(IntPredicate predicate)Here, parameter predicate is the stateless predicate to apply to elements of this streamCreate an IntStreamIntStream intStream = IntStream.of(15, 25, 50, 60, 80, 100, 130, 150);Here, set a condition that returns whether no elements of this stream match the provided predicate. We are checking for none of the value less than 10boolean res = intStream.noneMatch(a -> a ... Read More

Advertisements