Found 4336 Articles for Java 8

IntStream asDoubleStream() method in Java

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

139 Views

The asDoubleStream() method in the IntStream class returns a DoubleStream consisting of the elements of this stream, converted to double.The syntax is as followsDoubleStream asDoubleStream()First, create an IntStreamIntStream intStream = IntStream.of(20, 30, 40, 50, 60, 70, 80);After that, convert it to double with asDoubleStream() methodDoubleStream doubleStream = intStream.asDoubleStream();The following is an example to implement IntStream asDoubleStream() method in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) { IntStream intStream = IntStream.of(20, 30, 40, 50, 60, 70, 80); DoubleStream doubleStream = intStream.asDoubleStream(); doubleStream.forEach(System.out::println); } }Output20.0 30.0 40.0 50.0 60.0 70.0 80.0

LocalTime compareTo() method in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

1K+ Views

Two LocalTime objects can be compared using the compareTo() method in the LocalTime class in Java. This method requires a single parameter i.e. the LocalTime object to be compared.If the first LocalTime object is greater than the second LocalTime object it returns a positive number, if the first LocalTime object is lesser than the second LocalTime object it returns a negative number and if both the LocalTime objects are equal it returns zero.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Main{    public static void main(String[] args){       LocalTime lt1 = LocalTime.parse("11:37:12");   ... Read More

IntStream forEachOrdered() method in Java

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

318 Views

The forEachOrdered() method in Java assures that each element is processed in order for streams that have a defined encounter order.The syntax is as followsvoid forEachOrdered(IntConsumer action)Here, the action parameter is a non-interfering action to be performed on the elements.Create an IntStream and add elements to the streamIntStream intStream = IntStream.of(50, 70, 80, 100, 130, 150, 200);Now, use the forEachOrdered() method to display the stream elements in orderintStream.forEachOrdered(System.out::println);The following is an example to implement IntStream forEachOrdered() method in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo { public static void main(String[] args) { ... Read More

The clear() method of AbstractSequentialList in Java

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

59 Views

The clear() method is inherited from the AbstractList class. It allows you to remove all the elements from the list.The syntax is as followspublic void clear()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 clear() 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(250);       absSequential.add(320);       absSequential.add(400);       absSequential.add(550);       absSequential.add(600);       absSequential.add(700);   ... Read More

The contains() method of AbstractSequentialList in Java

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

89 Views

The contains() method of AbstractSequentialList in Java is used to check whether an element is in the Collection.The syntax is as followspublic boolean contains(Object ob)Here, ob is the element to be checked. 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 contains() 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(250); ... Read More

LongStream noneMatch() method in Java

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

93 Views

The noneMatch() method of the LongStream class in Java returns whether no elements of this stream match the provided predicate.The syntax is as followsboolean noneMatch(LongPredicate predicate)Here, the parameter predicate is a stateless predicate to apply to elements of this stream. However, LongPredicate in the syntax represents a predicate (boolean-valued function) of one long-valued argument.To use the LongStream class in Java, import the following packageimport java.util.stream.LongStream;The method returns true if either no elements of the stream match the provided predicate or the stream is empty. The following is an example to implement LongStream noneMatch() method in JavaExample Live Demoimport java.util.stream.LongStream; public class ... Read More

IntStream peek() method in Java

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

570 Views

The peek() method in the IntStream class in Java returns a stream consisting of the elements of this stream. It additionally performs the provided action on each element as elements are consumed from the resulting stream.The syntax is as followsIntStream peek(IntConsumer action)Here, the parameter action is a non-interfering action to perform on the elements as they are consumed from the stream. The IntConsumer represents an operation that accepts a single int-valued argument and returns no result.The following is an example to implement IntStream peek() method in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo { public static ... Read More

IntStream asLongStream() method in Java

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

211 Views

The asLongStream() method of the IntStream class returns a LongStream consisting of the elements of this stream, converted to long.The syntax is as followsLongStream asLongStream()Create an IntStream and add some elements in the StreamIntStream intStream = IntStream.of(30, 40, 60, 70, 90, 110, 140, 150);Now, use the asLongStream() method to convert it to longLongStream longStream = intStream.asLongStream();The following is an example to implement IntStream asLongStream() method in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { IntStream intStream = IntStream.of(30, 40, 60, 70, 90, ... Read More

DoubleStream distinct() method in Java

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

79 Views

The distinct() method of the DoubleStream class returns a stream consisting of the distinct elements of this stream.The syntax is as followsDoubleStream distinct()To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;Create DoubleStream and add some elements to the streamDoubleStream doubleStream = DoubleStream.of(39.8, 78.7, 64.7, 78.7, 47.8, 89.7, 78.7);Now, to get the distinct elements, use the distinct() methoddoubleStream.distinct() The following is an example to implement DoubleStream distinct() method in Java. We have repeated elements in the streamExample Live Demoimport java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { ... Read More

The remove() method of Java AbstractSequentialList class

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

53 Views

The remove() method of the AbstractSequentialList class removes the element at the specified position in this list.The syntax is as followsE remove(int index)Here, index is the index of the element to be removed. 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 remove() 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(25); ... Read More

Advertisements