Found 4336 Articles for Java 8

How to add elements to AbstractCollection class in Java?

Anvi Jain
Updated on 30-Jul-2019 22:30:25

81 Views

To add elements to the AbstractCollection class, use the add() method. For example −absCollection.add("These"); absCollection.add("are"); absCollection.add("demo");To work with AbstractCollection class in Java, import the following package −import java.util.AbstractCollection;The following is an example to add elements to AbstractCollection class in Java −Example Live Demoimport java.util.ArrayList; import java.util.AbstractCollection; public class Demo {    public static void main(String[] args) {       AbstractCollection absCollection = new ArrayList();       absCollection.add("These");       absCollection.add("are");       absCollection.add("demo");       absCollection.add("elements");       System.out.println("Displaying elements in the AbstractCollection: " + absCollection);    } }OutputDisplaying elements in the AbstractCollection: [These, ... Read More

LongStream flatMap() method in Java

Smita Kapse
Updated on 30-Jul-2019 22:30:25

58 Views

The flatMap() method in LongStream class returns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.The syntax is as follows −LongStream flatMap(LongFunction

LongStream forEachOrdered() method in Java

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

63 Views

The forEachOrdered() method in Java performs an action for each element of this stream, guaranteeing that each element is processed in encounter order for streams that have a defined encounter order.The syntax is as follows −void forEachOrdered(LongConsumer action)Here, parameter wrapper is a non-interfering action to perform on the elements. LongConsumer represents an operation that accepts a single long-valued argument and returns no result.To use the LongStream class in Java, import the following package −import java.util.stream.LongStream;The following is an example to implement LongStream forEachOrdered() method in Java −Example Live Demoimport java.util.*; import java.util.stream.LongStream; public class Demo {    public static void ... Read More

IntStream concat() method in Java

Anvi Jain
Updated on 30-Jul-2019 22:30:25

201 Views

The concat() method in the Java IntStream class forms a concatenated stream. The elements of this stream are all the elements of the first stream followed by all the elements of the second stream.The syntax is as follows −static IntStream concat(IntStream one, IntStream two)Here, the parameter one is the first stream, whereas two is the second stream. The method returns the concatenated result of the stream one and two.Let us create two IntStream and add some elements −IntStream intStream1 = IntStream.of(10, 20, 30, 40, 50); IntStream intStream2 = IntStream.of(60, 70, 80, 90);Now, to concate both the streams, use the concat() ... Read More

The equals() method of AbstractSequentialList in Java

Smita Kapse
Updated on 30-Jul-2019 22:30:25

70 Views

The equals() method is inherited from the AbstractList class in Java. It is used to check the object for equality with this list. It returns TRUE if the object is equal to this list, else FALSE is returned.The syntax is as follows −public boolean equals(Object o)Here, o is the object to be compared for equality with this list.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 equals() method in JavaExample Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo {    public static void main(String[] args) { ... Read More

The subList() method of AbstractSequentialList in Java

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

84 Views

The subList() method returns a part of this list between the specified fromIndex, inclusive, and toIndex, exclusive. Get a sublist using the method by setting the range as the two parameters.The syntax is as follows −public List subList(int fromIndex, int toIndex)Here, the parameter fromIndex is the low endpoint (inclusive) of the subList, whereas toIndex is the high endpoint (exclusive) of the subListTo work with the AbstractSequentialList class in Java, you need to import the following package −import java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList subList() method in Java −Example Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo {   ... Read More

The set() method of Java AbstractSequentialList class

Anvi Jain
Updated on 30-Jul-2019 22:30:25

72 Views

The set() method of the AbtstractSequentialList class is used to replace the element at the specified position in this list with the specified element. It returns the element which is replaced. The syntax is as follows −E set(int index, E element)Here, the index is the index of the element to replace. The ele is the element to be stored at the specified position.To work with the AbstractSequentialList class in Java, you need to import the following package −import java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList set() method in Java −Example Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo { ... Read More

DoubleStream mapToObj() method in Java

Smita Kapse
Updated on 30-Jul-2019 22:30:25

130 Views

The mapToObj() method of the DoubleStream class returns an object-valued Stream consisting of the results of applying the given function to the elements of this stream.The syntax is as follows − Stream mapToObj(DoubleFunction

How to generate Infinite Stream of Double in Java using DoubleStream.generate()

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

58 Views

The DoubleStream.generate() method returns an infinite sequential unordered stream where each element is generated by the provided DoubleSupplier.The syntax is as follows −static DoubleStream generate(DoubleSupplier s)Here, s is the DoubleSupplier for generated elements. The DoubleSupplier represents a supplier of double-valued results.To use the DoubleStream class in Java, import the following package −import java.util.stream.DoubleStream;The following is an example to generate Infinite stream of Double in Java with DoubleStream.generate() method −Exampleimport java.util.stream.*; import java.util.*; public class Demo {    public static void main(String[] args) {       Random r = new Random();       DoubleStream.generate(r::nextDouble).forEach(System.out::println);    } }Here is ... Read More

IntStream range() method in Java

Anvi Jain
Updated on 30-Jul-2019 22:30:25

9K+ Views

The range() method in the IntStream class in Java is used to return a sequential ordered IntStream from startInclusive to endExclusive by an incremental step of 1. This includes the startInclusive as well.The syntax is as follows −static IntStream range(int startInclusive, int endExclusive)Here, the parameter startInclusive includes the starting value, whereas endExclusive excludes the last valueTo work with the IntStream class in Java, import the following package −import java.util.stream.IntStream;Create an IntStream and add stream elements in a range using range() method. This returns a sequential ordered IntStream by an incremental step of 1 within the range −intStream.forEach(System.out::println);The following is an ... Read More

Advertisements