Found 4332 Articles for Java 8

LocalTime plusHours() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

34 Views

An immutable copy of a LocalTime object where some hours are added to it can be obtained using the plusHours() method in the LocalTime class in Java. This method requires a single parameter i.e. the number of hours to be added and it returns the LocalTime object with the added hours.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalTime lt = LocalTime.now();       System.out.println("The current LocalTime is: " + lt);       System.out.println("The LocalTime with 3 hours added is: ... Read More

LocalTime plusNanos() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

57 Views

An immutable copy of a LocalTime object where some nanoseconds are added to it can be obtained using the plusNanos() method in the LocalTime class in Java. This method requires a single parameter i.e. the number of nanoseconds to be added and it returns the LocalTime object with the added nanoseconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalTime lt = LocalTime.now();       System.out.println("The current LocalTime is: " + lt);       System.out.println("The LocalTime with 1000 nanoseconds added is: ... Read More

Collectors minBy() method in Java 8

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

344 Views

The minBy() method of the Collectors class in Java 8 returns a Collector that produces the minimum element according to a given Comparator, described as an OptionalThe syntax is as followsstatic Collector

LongStream mapToInt() method in Java

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

759 Views

The mapToInt() method returns an IntStream consisting of the results of applying the given function to the elements of this stream.The syntax is as followsmapToInt(LongToIntFunction mapper)Here, the parameter mapper is the stateless function applied to each element.Declare LongStream and add some elementsLongStream longStream = LongStream.of(1000L, 13000L, 18000L);Now, use the IntStream and mapToInt()IntStream intStream = longStream.mapToInt(val -> (int) val);The following is an example to implement LongStream mapToInt() 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) {       LongStream longStream = LongStream.of(1000L, 13000L, 18000L);       IntStream intStream = ... Read More

What is AbstractSequentialList class in Java?

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

292 Views

The AbstractSequentialList class provides an implementation of the List interface. For an unmodifiable list, implement the list iterator's hasNext, next, hasPrevious, previous and index methods. For a modifiable list the programmer should implement the list iterator's set method.The syntax is as followspublic abstract class AbstractSequentialList extends AbstractListTo work with the AbstractSequentialList class in Java, you need to import the following packageimport java.util.AbstractSequentialList;First, create an AbstractSequentialList classAbstractSequentialList absSequential = new LinkedList();Now, add elementsabsSequential.add("Accessories"); absSequential.add("Home Decor"); absSequential.add("Books"); bsSequential.add("Stationery");Let us see an example to implement the AbstractSequentialList class in JavaExample Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo {    public static void main(String[] ... Read More

The toString() method of Java AbstractCollection class

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

220 Views

The toString() method of the AbstractCollection class is used to return the string representation of the elements of this collection.The syntax is as followspublic String toString()To work with AbstractCollection class in Java, import the following packageimport java.util.AbstractCollection;The following is an example to implement AbstractCollection toString() method in JavaExample Live Demoimport java.util.ArrayList; import java.util.AbstractCollection; public class Demo {    public static void main(String[] args) {       AbstractCollection absCollection = new ArrayList();       absCollection.add("HDD");       absCollection.add("Earphone");       absCollection.add("Headphone");       absCollection.add("Card Reader");       absCollection.add("SSD");       absCollection.add("Pen Drive");       ... Read More

The toArray(T[] a) T method of Java AbstractCollection class

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

82 Views

The difference between toArray() and toArray(T[] arr) in Java AbstractCollection 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, arr is the array into which the elements of this collection are to be stored.To work with AbstractCollection class in Java, import the following packageimport java.util.AbstractCollection;The following is an example to implement AbstractCollection toArray() method in JavaExample Live Demoimport java.util.ArrayList; import java.util.AbstractCollection; public class Demo { ... Read More

ArrayBlockingQueue add() method in Java

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

64 Views

To add elements to the ArrayBlockingQueue class, use the add() method.The syntax is as followsboolean add(E ele)Here, ele is the element to be added to the queue. To work with ArrayBlockingQueue class, you need to import the following packageimport java.util.concurrent.ArrayBlockingQueue;The following is an example to add elements in Java ArrayBlockingQueue classExample Live Demoimport java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) {       ArrayBlockingQueue q = new ArrayBlockingQueue(7);       q.add(100); q.add(250); q.add(300); q.add(450); q.add(550); q.add(600); q.add(700);       System.out.println("ArrayBlockingQueue = " + q);    } }OutputArrayBlockingQueue = [100, 250, 300, 450, 550, 600, 700]

DoubleStream summaryStatistics() method in Java

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

67 Views

The summaryStatistics() method of the DoubleStream class returns a DoubleSummaryStatistics describing various summary data about the elements of this stream. This is a special case of a reduction.The syntax is as followsDoubleSummaryStatistics summaryStatistics()Here, DoubleSummaryStatistics is a state object for collecting statistics such as count, min, max, average, etc. It works with streams. To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;First, create a DoubleStream and add some elementsDoubleStream doubleStream = DoubleStream.of(20.5, 35.8, 45.9, 50.8, 80.7);Now, get the statisticsDoubleSummaryStatistics details = doubleStream.summaryStatistics();The following is an example to implement DoubleStream summaryStatistics() methodExample Live Demoimport java.util.stream.DoubleStream; import java.util.DoubleSummaryStatistics; public class Demo ... Read More

LongStream map() method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

83 Views

The map() method of the LongStream class in Java returns a stream consisting of the results of applying the given function to the elements of this stream.The syntax is as follows:LongStream map(LongUnaryOperator mapper)Here, the parameter mapper is a stateless function to apply to each element. The LongUnaryOperator represents an operation on a single long-valued operand that produces a long-valued result.To use the LongStream class in Java, import the following package:import java.util.stream.LongStream;Create a LongStream and add some elements:LongStream longStream1 = LongStream.of(15L, 30L, 45L, 67L, 80L);Now, create another LongStream and map it to a condition set for the elements of longStream1:LongStream longStream2 ... Read More

Advertisements