Found 4336 Articles for Java 8

LocalTime get() method in Java

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

101 Views

The value of the specified field from the LocalTime can be obtained using the get() method in the LocalTime class in Java. This method requires a single parameter i.e. ChronoField that is required and it returns the value of the specified field from the LocalTime.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; import java.time.temporal.ChronoField; public class Main{    public static void main(String[] args){       LocalTime lt = LocalTime.parse("23:15:30");       System.out.println("The LocalTime is: " + lt);       System.out.println("The MINUTE_OF_HOUR is: " +       lt.get(ChronoField.MINUTE_OF_HOUR));    } }outputThe LocalTime is: 23:15:30 ... Read More

LocalTime getMinute() method in Java

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

136 Views

The minute of the hour for a particular LocalTime can be obtained using the getMinute() method in the LocalTime class in Java. This method requires no parameters and it returns the minute of the hour in the range of 0 to 59.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalTime lt = LocalTime.parse("23:15:30");       System.out.println("The LocalTime is: " + lt);       System.out.println("The minute is: " + lt.getMinute());    } }outputThe LocalTime is: 23:15:30 The minute is: 15Now let us ... Read More

Set Decade value in JavaTuples

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

82 Views

To set a new value in the Decade Tuple, you need to use the setAtX() method. Here, X is the index wherein you want to set the value. For example, setAt2() sets the value at index 2. The value to be included is to be set as the value in the parameter, likesetAt2(“Amit”);Let us first see what we need to work with JavaTuples. To work with Decade class in JavaTuples, you need to import the following packageimport org.javatuples.Decade;Note Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java ... Read More

Fetch the value from Decade Tuple in Java

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

72 Views

To fetch the value from Decade Tuple in Java, use the getAtX() method. Here, X represents the index value like getAt1() at index 1. This will return the element at index 1 in the Tuple.Let us first see what we need to work with JavaTuples. To work with Decade class in JavaTuples, you need to import the following packageimport org.javatuples.Decade;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 ... Read More

ArrayBlockingQueue size() Method in Java

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

88 Views

To get the number of elements in the queue, use the size() method of the ArrayBlockingQueue class.The syntax is as followsint size()To work with ArrayBlockingQueue class, you need to import the following packageimport java.util.concurrent.ArrayBlockingQueue;The following is an example to implement size() 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); ... Read More

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

Advertisements