Found 9326 Articles for Object Oriented Programming

The add() method of CopyOnWriteArrayList in Java

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

118 Views

Two types of add() methods are available in the CopyOnWriteArrayList class: add(E e) methodTo add elements in CopyOnWriteArrayList class in Java, use the add() method. Here, the element is appended to the end of the list.The syntax is as followsboolean add(E e)Here, the parameter e is the element to be appended to this list.To work with CopyOnWriteArrayList class, you need to import the following packageimport java.util.concurrent.CopyOnWriteArrayList;The following is an example to add elements in the CopyOnWriteArrayList class in JavaExample Live Demoimport java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] args) {       CopyOnWriteArrayList arrList = new CopyOnWriteArrayList(); ... Read More

MonthDay from() method in Java

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

39 Views

An instance of a MonthDay object can be obtained from a Temporal object using the from() method in the MonthDay class in Java. This method requires a single parameter i.e. the Temporal object and it returns the MonthDay object that is obtained from the Temporal object.A program that demonstrates this is given as followsExample Live Demoimport java.time.*;    public class Main {       public static void main(String[] args) {       MonthDay md = MonthDay.from(ZonedDateTime.now());       System.out.println("The MonthDay is: " + md);    } }OutputThe MonthDay is: --02-22Now let us understand the above program.The instance of ... Read More

MonthDay atYear() method in Java

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

57 Views

The MonthDay can be combined with a year to create a LocalDate using the atYear() method in the MonthDay class in Java. This method requires a single parameter i.e.the year and it returns the LocalDate created by combining MonthDay with the year.A program that demonstrates this is given as follows:Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       MonthDay md = MonthDay.parse("--02-22");       System.out.println("The MonthDay is: " + md);       LocalDate ld = md.atYear(2019);       System.out.println("The LocalDate is: " + ld);    } }OutputThe MonthDay is: ... Read More

The contains() method of CopyOnWriteArrayList in Java

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

79 Views

The contains() method of the CopyOnWriteArrayList class is used to get the specified element. It returns TRUE if the element is in the List, else FALSE is returned.The syntax is as followsboolean contains(Object ob)Here, ob is the element to be checked for existence. 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 contains() method in JavaExample Live Demoimport java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] args) {       CopyOnWriteArrayList arrList = new CopyOnWriteArrayList();       arrList.add(100);       arrList.add(250);       ... Read More

MonthDay getDayOfMonth() method in Java

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

70 Views

The day of the month for a particular MonthDay can be obtained using the getDayOfMonth() method in the MonthDay class in Java. This method requires no parameters and it returns the day of the month which can be in the range of 1 to 31.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-22");       System.out.println("The MonthDay is: " + md);       System.out.println("The day of the month is: " + md.getDayOfMonth());    } }OutputThe MonthDay is: --02-22 ... Read More

MonthDay equals() method in Java

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

78 Views

The equality of two MonthDay objects can be determined using the equals() method in the MonthDay class in Java. This method requires a single parameter i.e. the MonthDay object to be compared. Also it returns true if both the MonthDay objects are equal 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-22");       MonthDay md2 = MonthDay.parse("--02-22");       System.out.println("The MonthDay md1 is: " + md1);       System.out.println("The MonthDay md2 is: " + ... Read More

MonthDay format() method in Java

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

59 Views

The MonthDay can be formatted with the specified formatter using the format() method in the MonthDay class in Java. This method requires a single parameter i.e. the MonthDay object to be formatted and it returns the formatted MonthDay with the specified formatter.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; import java.time.temporal.*; import java.time.format.DateTimeFormatter;    public class Demo {       public static void main(String[] args) {       MonthDay md = MonthDay.parse("--02-22");       LocalDate ld = md.atYear(2019);       System.out.println("The MonthDay is: " + md);       DateTimeFormatter dtf = DateTimeFormatter.ofPattern("YYYY-MM-dd"); ... Read More

MonthDay compareTo() method in Java

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

95 Views

Two MonthDay objects can be compared using the compareTo() method in the MonthDay class in Java. This method requires a single parameter i.e. the MonthDay object to be compared.If the first MonthDay object is greater than the second MonthDay object it returns a positive number, if the first MonthDay object is lesser than the second MonthDay object it returns a negative number and if both the MonthDay objects are equal it returns zero.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       MonthDay md1 = ... Read More

IntStream flatMap() method in Java

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

611 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

68 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

Advertisements