Found 34469 Articles for Programming

The indexOf() method of CopyOnWriteArrayList class in Java

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

243 Views

The indexOf() method of the CopyOnWriteArrayList class is used to get the index of the first occurrence of an element. The method has two two forms. Let us see them one by oneindexOf(Object o) methodThe indexOf(Object o) is used to get the index of the first occurrence of an element.The syntax is as followsindexOf(Object o)Here, o is the element for which you want the index. 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 indexOf() method in JavaExample Live Demoimport java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void ... Read More

The toArray(T[] a) method of CopyOnWriteArrayList in Java

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

61 Views

The difference between toArray() and toArray(T[] arr) of the CopyOnWriteArrayList class is that both the methods returns an array containing all of the elements in this collection, but the latter has some additional features i.e. the runtime type of the returned array is that of the specified array.The syntax is as followspublic T[] toArray(T[] arr)Here, the parameter arr is the array into which the elements of the list are to be stored.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 toArray() method in JavaExample Live Demoimport java.util.Arrays; import ... Read More

LocalTime ofNanoOfDay() method in Java

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

75 Views

A LocalTime object can be obtained using the nanoseconds of the day with the ofNanoOfDay() method in the LocalTime class in Java. This method requires a single parameter i.e. the nanoseconds of the day and it returns the LocalTime object for the nanoseconds of the dayA program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args){       long nanoSeconds = 1000000000;       System.out.println("The nanoseconds of the day: " + nanoSeconds);       System.out.println("The LocalTime is: " + LocalTime.ofNanoOfDay(nanoSeconds));    } }outputThe nanoseconds of the day: ... Read More

DoubleStream of() method in Java

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

148 Views

The DoubleStream class in Java the following two forms of the of() methodThe following of() method returns a sequential DoubleStream containing a single element. Here is the syntaxstatic DoubleStream of(double t)Here, parameter t is the single element.The following of() method returns a sequential ordered stream whose elements are the specified valuesstatic DoubleStream of(double… values)Here, the parameter values are the elements of the new stream.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream of() method in JavaExample Live Demoimport java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) ... Read More

DoubleStream filter() method in Java

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

87 Views

The filter() method of the DoubleStream class returns a stream consisting of the elements of this stream that match the given predicate.The syntax is as followsDoubleStream filter(DoublePredicate predicate)The parameter predicate is a stateless predicate to apply to each element to determine if it should be included.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;Create a DoubleStream and add some elementsDoubleStream doubleStream = DoubleStream.of(20.5, 35.7, 50.8, 67.9, 89.8, 93.1);Filter and display the element equal to a 50.8, if it’s presentdoubleStream.filter(a -> a == 50.8) The following is an example to implement DoubleStream filter() method in JavaExample Live Demoimport java.util.stream.DoubleStream; ... Read More

IntStream asDoubleStream() method in Java

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

141 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

Advertisements