Found 34469 Articles for Programming

IntStream flatMap() method in Java

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

617 Views

The flatMap() method of the IntStream 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 followsIntStream flatMap(IntFunction

MonthDay isValidYear() Method in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

70 Views

It can be checked if a year is valid or not for a MonthDay object using the isValidYear() method in the MonthDay class in Java. This method requires a single parameter i.e. the year which is to be checked. Also, it returns true if the year is valid for a MonthDay object and false if the year is not valid for a MonthDay object.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       MonthDay md = MonthDay.parse("--02-21");       System.out.println("The MonthDay is: " + ... Read More

IntStream map() method in Java

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

2K+ Views

The IntStream map() method returns the new stream consisting of the results of applying the given function to the elements of this stream.The syntax is as followsIntStream map(IntUnaryOperator mapper)Here, mapper parameter is a non-interfering, stateless function to apply to each elementCreate an IntStream and add some elementsIntStream intStream1 = IntStream.of(20, 35, 40, 55, 60);Now, map it with the new IntStream and display the updated stream elements applying the condition in the map() functionIntStream intStream2 = intStream1.map(a -> (a + a));The following is an example to implement IntStream map() method in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo {   ... Read More

MonthDay isSupported() Method in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

66 Views

It can be checked if a ChronoField is supported by the MonthDay class or not by using the isSupported() method in the MonthDay class in Java. This method requires a single parameter i.e. the ChronoField to check. It returns true if the ChronoField is supported by the MonthDay class and false otherwise.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; import java.time.temporal.*; public class Demo {    public static void main(String[] args) {       MonthDay md = MonthDay.now();       System.out.println("The MonthDay is: " + md);       boolean flag = md.isSupported(ChronoField.MONTH_OF_YEAR);     ... Read More

The isEmpty() method of CopyOnWriteArrayList method in Java

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

78 Views

To check whether the list is empty or not, use the isEmpty() method. TRUE is returned if the list is empty, else FALSE is the return value.The syntax is as followsboolean isEmpty()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 isEmpty() method in JavaExample Live Demoimport java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] args) {       CopyOnWriteArrayList arrList = new CopyOnWriteArrayList();       arrList.add(30);       arrList.add(40);       arrList.add(60);       arrList.add(70);       arrList.add(90);       ... Read More

MonthDay isAfter() Method in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

74 Views

It can be checked if a particular MonthDay is after the other MonthDay in a timeline using the isAfter() method in the MonthDay class in Java. This method requires a single parameter i.e. the MonthDay object that is to be compared. It returns true if the MonthDay object is after the other MonthDay object and false otherwise.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       MonthDay md1 = MonthDay.parse("--02-25");       MonthDay md2 = MonthDay.parse("--02-21");       System.out.println("The MonthDay md1 is: " ... Read More

MonthDay isBefore() Method in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

73 Views

It can be checked if a particular MonthDay is before the other MonthDay in a timeline using the isBefore() method in the MonthDay class in Java. This method requires a single parameter i.e. the MonthDay object that is to be compared. It returns true if the MonthDay object is before the other MonthDay object and false otherwise.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       MonthDay md1 = MonthDay.parse("--02-15");       MonthDay md2 = MonthDay.parse("--02-21");       System.out.println("The MonthDay md1 is: " ... Read More

MonthDay range() method in Java

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

63 Views

The range of values for a ChronoField can be obtained using the range() method in the MonthDay class in Java. This method requires a single parameter i.e. the ChronoField for which the range of values is required and it returns the range of values.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; import java.time.temporal.ChronoField; import java.time.temporal.ValueRange; public class Main {    public static void main(String[] args) {       MonthDay md = MonthDay.parse("--02-21");       System.out.println("The MonthDay is: " + md);       ValueRange range = md.range(ChronoField.DAY_OF_MONTH);       System.out.println("The range of DAY_OF_MONTH is: ... Read More

The listIterator() method of CopyOnWriteArrayList in Java starting at a specified position

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

86 Views

The listIterator() method CopyOnWriteArrayList class returns a list iterator over the elements in this list, beginning at the specified position in the list.The syntax is as followspublic ListIterator listIterator(int index)Here, index is the index of the first element to be returned from the list iterator.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 listIterator() method in Java. We have set the index as 3, therefore, the list would be iterated from index 3Example Live Demoimport java.util.Iterator; import java.util.ListIterator; import java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] ... Read More

MonthDay hashCode() method in Java

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

81 Views

The hash code value of the MonthDay can be obtained using the hashCode() method in the MonthDay class in Java. This method requires no parameters and it returns the hash code value of the MonthDay.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {         MonthDay md = MonthDay.parse("--02-21");       System.out.println("The MonthDay is: " + md);       System.out.println("The hash code is: " + md.hashCode());    } }outputThe MonthDay is: --02-21 The hash code is: 149Now let us understand the above program.First ... Read More

Advertisements