Found 4330 Articles for Java 8

LocalDateTime withDayOfMonth() method in Java

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

50 Views

An immutable copy of a LocalDateTime with the day of month altered as required is done using the method withDayOfMonth() in the LocalDateTime class in Java. This method requires a single parameter i.e. the day of month that is to be set in the LocalDateTime and it returns the LocalDateTime with the day of month altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalDateTime ldt1 = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt1);       LocalDateTime ... Read More

IntStream findAny() method in Java

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

86 Views

The findAny() method of the IntStream class in Java is used to return an OptionalInt describing some element of the stream, or an empty OptionalInt if the stream is empty.The syntax is as follows −OptionalInt findAny()Here, OptionalInt is a container object which may or may not contain an int value.Create an IntStream and add some elements −IntStream intStream = IntStream.of(20, 35, 50, 60, 80, 100);Now, return any of the element of the stream using findAny() in Java −OptionalInt res = intStream.findAny();The following is an example to implement IntStream findAny() method in Java −Example Live Demoimport java.util.*; import java.util.stream.IntStream; public class ... Read More

The iterator() method of Java AbstractCollection class

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

92 Views

The iterator() method of the AbstractCollection class in Java is used to return an iterator over the elements contained in this collection.The syntax is as follows −public abstract Iterator iterator()To work with AbstractCollection class in Java, import the following package −import java.util.AbstractCollection;For Iterator, import the following package −import java.util.Iterator;The following is an example to implement the AbstractCollection iterator() method in Java −Example Live Demoimport java.util.Iterator; import java.util.ArrayList; import java.util.AbstractCollection; public class Demo {    public static void main(String[] args) {       AbstractCollection absCollection = new ArrayList();       absCollection.add("Laptop");       absCollection.add("Tablet");       absCollection.add("Mobile"); ... Read More

The isEmpty() method of Java AbstractCollection class

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

236 Views

The isEmpty() method of the AbstractCollection class checks whether the collection is empty or not i.e. whether it has zero elements. It returns if the Collectionn has no elements.The syntax is as follows −public boolean isEmpty()To work with AbstractCollection class in Java, import the following package −import java.util.AbstractCollection;The following is an example to implement AbstractCollection isEmpty() method 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("Laptop");       absCollection.add("Tablet");       absCollection.add("Mobile");       absCollection.add("E-Book ... Read More

The containsAll() method of Java AbstractCollection class

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

240 Views

The containsAll() method checks for all the elements in the specified collection. It returns TRUE if this collection has all the elements. The methods check for each element one by one to see if it's contained in this collection.The syntax is as follows −public boolean containsAll(Collection c)To work with AbstractCollection class in Java, import the following package −import java.util.AbstractCollection;The following is an example to implement AbstractCollection containsAll() method in Java −Example Live Demoimport java.util.ArrayList; import java.util.AbstractCollection; public class Demo {    public static void main(String[] args) {       AbstractCollection absCollection1 = new ArrayList();       absCollection1.add("These");   ... Read More

Fetch the value from an Octet Tuple in Java

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

71 Views

To fetch the value from an Octet Tuple, use the getValueX() method. Here X is the index for which you want the value.For example, to fetch the 5th element i.e. 4th index, use the getValueX() method as −getValue(4);Let us first see what we need to work with JavaTuples. To work with Octet class in JavaTuples, you need to import the following package −import org.javatuples.Octet;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. ... Read More

Create Octet Tuple from a List collection in Java

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

81 Views

Create Octel Tuple from List collection as well using the fromCollection() method in Java. Let us first see what we need to work with JavaTuples. To work with Octet class in JavaTuples, you need to import the following package −import org.javatuples.Octet;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 JavaTuples −Steps − How to run JavaTuples program in EclipseThe following is an ... Read More

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

Advertisements