Found 9326 Articles for Object Oriented Programming

Search for a value in Java KeyValue Tuple

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

64 Views

To search for a value in KeyValue Tuple, use the contains() method. Here, the value to be searched should be set as the parameter of the method. The return value is a boolean i.e. TRUE, if the value exists, else FALSE. Let us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following packageimport org.javatuples.KeyValue;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 ... Read More

Set value in the JavaTuples KeyValue class

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

76 Views

To set value in the JavaTuples KeyValue class, you need to use the setValue() method. Let us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following packageimport org.javatuples.KeyValue;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: How to run JavaTuples program in EclipseThe following is an example to set ... Read More

IntStream anyMatch() method in Java

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

472 Views

The anyMatch() method in the IntStream class in Java returns whether any elements of this stream match the provided predicate.The syntax is as followsboolean anyMatch(IntPredicate predicate)To work with the IntStream class in Java, import the following packageimport java.util.stream.IntStream;Here, the predicate parameter is a stateless predicate to apply to elements of this stream.Create an IntStream and add some elementsIntStream intStream = IntStream.of(20, 40, 60, 80, 100);Now, use the anyMatch() method to set for a condition. If any of the element match with the condition, TRUE is returnedboolean res = intStream.anyMatch(a -> a < 50); The following is an example to implement ... Read More

The toArray() method of AbstractSequentialList in Java

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

56 Views

The toArray() method is inherited from the AbstractCollection() method. It returns an array containing similar elements in this collection.The syntax is as followspublic Object[] toArray()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 toArray() 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(210);       absSequential.add(290);       absSequential.add(350);       absSequential.add(490);       absSequential.add(540);       absSequential.add(670);     ... Read More

IntStream forEach() method in Java

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

349 Views

The forEach() method is used in Java to perform an action for each element of this stream. Display the stream using the forEach() method in Java IntStreamThe syntax is as followsvoid forEach(IntConsumer action)Here, action is a non-interfering action to perform on the elements.Create IntStream and add elementsIntStream intStream = IntStream.of(15, 30, 40, 60, 75, 90);Now, display the streamintStream.forEach(System.out::println);The following is an example to implement IntStream forEach() method in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream intStream = IntStream.of(15, 30, 40, 60, 75, 90);       intStream.forEach(System.out::println); ... Read More

IntStream noneMatch() method in Java

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

623 Views

The noneMatch() method in Java returns whether no elements of this stream match the provided predicate. The true boolean value is returned if either no elements of the stream match the provided predicate or the stream is empty.The syntax is as followsBoolean noneMatch(IntPredicate predicate)Here, parameter predicate is the stateless predicate to apply to elements of this streamCreate an IntStreamIntStream intStream = IntStream.of(15, 25, 50, 60, 80, 100, 130, 150);Here, set a condition that returns whether no elements of this stream match the provided predicate. We are checking for none of the value less than 10boolean res = intStream.noneMatch(a -> a ... Read More

IntStream of() method in Java

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

365 Views

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

DoubleStream forEachOrdered() method in Java

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

90 Views

The forEachOrdered() method of the DoubleStream class in Java performs an action for each element of this stream. This assures that each element is processed in encounter order for streams that have a defined encounter order.The syntax is as followsvoid forEachOrdered(DoubleConsumer action)Here, DoubleConsumer represents an operation that accepts a single double-valued argument and returns no result. The parameter action is a non-interfering action to perform on the elements.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream forEachOrdered() method in Java:Example Live Demoimport java.util.stream.DoubleStream; public class Demo {    public static void ... Read More

LocalDateTime hashCode() method in Java

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

107 Views

The hash code value of the LocalDateTime can be obtained using the hashCode() method in the LocalDateTime class in Java. This method requires no parameters and it returns the hash code value of the LocalDateTime.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt);       System.out.println("The hash code is: " + ldt.hashCode());    } }OutputThe LocalDateTime is: 2019-02-18T23:15:30 The hash code is: -388538188Now let us understand the above program.First ... Read More

LocalDateTime getSecond() method in Java

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

47 Views

The second of minute for a particular LocalDateTime can be obtained using the getSecond() method in the LocalDateTime class in Java. This method requires no parameters and it returns the second of the minute in the range of 0 to 59.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt);       System.out.println("The second is: " + ldt.getSecond());    } }OutputThe LocalDateTime is: 2019-02-18T23:15:30 The second is: 30Now let us ... Read More

Advertisements