Found 4332 Articles for Java 8

The hashCode() method of CopyOnWriteArrayList method in Java

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

80 Views

To get the hash code value of the list, you need to use the hashCode() method of the CopyOnWriteArrayList class.The syntax is as followspublic int hashCode()To work with CopyOnWriteArrayList class, you need to import the following packageimport java.util.concurrent.CopyOnWriteArrayList;The following is an example to implement CopyOnWriteArrayList class hashCode() method in JavaExample Live Demoimport java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] args) {       CopyOnWriteArrayList arrList = new CopyOnWriteArrayList();       arrList.add(30);       arrList.add(40);       arrList.add(60);       arrList.add(70);       arrList.add(90);       arrList.add(100);       arrList.add(120);   ... Read More

ArrayBlockingQueue remainingCapacity() Method in Java

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

53 Views

The remainingCapacity() method of the ArrayBlockingQueue class in Java is used to return the number of additional elements that the queue can adopt without blocking.The syntax is as followsint remainingCapacity()To work with ArrayBlockingQueue class, you need to import the following packageimport java.util.concurrent.ArrayBlockingQueue;The following is an example to implement remainingCapacity() method of Java ArrayBlockingQueue classExample Live Demoimport java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) throws InterruptedException {       ArrayBlockingQueue q = new ArrayBlockingQueue(10);       q.add(120);       q.add(400);       q.add(450);       q.add(500);       System.out.println("ArrayBlockingQueue = " + ... Read More

DoubleStream.Builder build() method in Java

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

69 Views

The build() method of the DoubleStream.Builder class builds the stream. It transitions this builder to the built state.The syntax is as followsDoubleStream build()To use the DoubleStream.Builder class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream.Builder build() method in Java:Example Live Demoimport java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream.Builder builder = DoubleStream.builder();       builder.add(34.5);       builder.add(87.1);       builder.add(35.6);       builder.add(66.1);       builder.add(36.8);       builder.add(77.4);       builder.add(88.2);       builder.add(68.9);       builder.build().forEach(System.out::println);    } }Output34.5 87.1 35.6 66.1 36.8 77.4 88.2 68.9

DoubleStream.Builder add() method in Java

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

71 Views

The add() method of the DoubleStream.Builder class in Java adds an element to the stream being built. The method returns this builder.The syntax is as followsdefault DoubleStream.Builder add(double ele)Here, ele is the element to be added to this stream.To use the DoubleStream.Builder class in Java, import the following packageimport java.util.stream.DoubleStream; Create DoubleStream.Builder: DoubleStream.Builder builder = DoubleStream.builder(); Now add some elements: builder.add(23.5); builder.add(33.1); builder.add(35.6); builder.add(53.1);The following is an example to implement DoubleStream.Builder add() method in JavaExample Live Demoimport java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream.Builder builder = DoubleStream.builder();       builder.add(23.5);   ... Read More

ArrayBlockingQueue take() method in Java

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

168 Views

The take() method of the ArrayBlockingQueue class fetch and removes the head of this queue, waiting if necessary until an element becomes available.The syntax is as followspublic E take() throws InterruptedExceptionTo work with ArrayBlockingQueue class, you need to import the following packageimport java.util.concurrent.ArrayBlockingQueue;The following is an example to implement take() method of Java ArrayBlockingQueue classExample Live Demoimport java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) throws InterruptedException {       ArrayBlockingQueue q = new ArrayBlockingQueue(10);       q.add(200);       q.add(310);       q.add(400);       q.add(450);       q.add(500);     ... Read More

Convert IntStream to String in Java

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

321 Views

If you have IntStream with ASCII values, then easily convert it to string using the below given example.For IntStream class, import the following packageimport java.util.stream.IntStream;Let’s say the following is our IntStreamIntStream stream = "Example".chars();Now, convert the IntStream to stringString str = stream.collect(StringBuilder::new,    StringBuilder::appendCodePoint,    StringBuilder::append).toString();The following is an example to convert IntStream to String in JavaExampleimport java.util.stream.IntStream; class Demo {    public static void main(String[] args) {       IntStream stream = "Example".chars();       System.out.println("The ASCII values...");       String str = stream.collect(StringBuilder::new,       StringBuilder::appendCodePoint,       StringBuilder::append).toString();       System.out.println("The ... Read More

DoubleStream sorted() method in Java

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

50 Views

The sorted() method of the DoubleStream class returns a stream consisting of the elements of this stream in sorted order.The syntax is as followsDoubleStream sorted()To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;Create a DoubleStream and add some elements to the streamDoubleStream doubleStream = DoubleStream.of(78.9, 90.4, 27.9, 20.6, 45.3, 18.5);Now, sort the elements of the streamdoubleStream.sorted().The following is an example to implement DoubleStream sorted() method in JavaExample Live Demoimport java.util.*; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream doubleStream = DoubleStream.of(78.9, 90.4, 27.9, 20.6, 45.3, 18.5);       ... Read More

Collectors toCollection() method in Java 8

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

852 Views

The toCollection() method of the Collectors class in Java returns a Collector that accumulates the input elements into a new Collection in encounter order.The syntax is as followsstatic Collector toCollection(Supplier collectionFactory)Here, the parameterT - Type of the input elementsC - Type of the resulting CollectionSupplier: A supplier of resultscollectionFactory - Supplier that returns a new, empty Collection of the appropriate typeTo work with Collectors class in Java, import the following packageimport java.util.stream.Collectors;The following is an example to implement toCollection() method in JavaExample Live Demoimport java.util.Collection; import java.util.TreeSet; import java.util.stream.Collectors; import java.util.stream.Stream; public class Demo {    public static void main(String[] ... Read More

How to create Ennead Tuple in Java?

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

72 Views

To create Ennead Tuple, you can use the with() method or even constructor. Let us see how to create Ennead Tuple and add elements to it with Constructor.Let us first see what we need to work with JavaTuples. To work with Ennead class in JavaTuples, you need to import the following packageimport org.javatuples.Ennead;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 ... Read More

The iterator() method of Java AbstractSequentialList class

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

57 Views

The iterator() method of the AbstractSequentialList class iterates over the elements in this list and returns it.The syntax is as followsIterator iterator()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 iterator() method in JavaExample Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; import java.util.Iterator; public class Demo {    public static void main(String[] args) {       AbstractSequentialList       absSequential = new LinkedList();       absSequential.add(10);       absSequential.add(25);       absSequential.add(60);       absSequential.add(70);       absSequential.add(195);       System.out.println("Elements ... Read More

Advertisements