Question

Consider the follow ArrayLis in Javat: ArrayList centennials = new ArrayList<>(); centennials.add(LocalDate.of(1776, Month.JULY, 4)); centennials.add(LocalDate.of(1876, Month.JULY,...

Consider the follow ArrayLis in Javat:

ArrayList centennials = new ArrayList<>();

centennials.add(LocalDate.of(1776, Month.JULY, 4));

centennials.add(LocalDate.of(1876, Month.JULY, 4));

centennials.add(LocalDate.of(1900, Month.JULY, 4));

centennials.add(LocalDate.of(1976, Month.JULY, 4));

centennials.add(LocalDate.of(2076, Month.JULY, 4));

As you can observe, a java program author has mistakenly entered a 1900 item into the ArrayList. Without removing the associated centennials.add(...) source line, write the code to remove the errant entry. Print out the resulting ArrayList and size as follows:

Before removal:

07/04/1776

07/04/1876

07/04/1900

07/04/1976

07/04/2076

size = 5

After removal:

07/04/1776

07/04/1876

07/04/1976

07/04/2076

size = 4

Hint: you should use the DateTimeFormatter class for formatting

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

import java.io.*;
import java.time.LocalDate;
import java.time.Month;
import java.util.*;
public class arraylist {
public static void main(String[] args)
{
ArrayList centennials=new ArrayList<>();

//Adding data to Array list
centennials.add(LocalDate.of(1776, Month.JULY, 4));
centennials.add(LocalDate.of(1876, Month.JULY, 4));
centennials.add(LocalDate.of(1900, Month.JULY, 4));
centennials.add(LocalDate.of(1976, Month.JULY, 4));
centennials.add(LocalDate.of(2076, Month.JULY, 4));

System.out.println("Before removel:\n");
System.out.println(centennials); //To print the dates before removal of 1990
System.out.println("Size="+centennials.size()); //Find the size of the array list before removel of 1990
centennials.remove(2); //Remove the element at index '2'
System.out.println("After removal:\n");
System.out.println(centennials); //To print the dates after removal of 1990
System.out.println("Size="+centennials.size()); //Find the size of the array list after removal of 1990
}

}

Output:

<terminated> arraylist [Java Application] C:\Program Files Vava\jdk1.8.0_73\bin\javaw.exe (19-Nov-2019, 11:44:07 PM) Before r

Add a comment
Know the answer?
Add Answer to:
Consider the follow ArrayLis in Javat: ArrayList centennials = new ArrayList<>(); centennials.add(LocalDate.of(1776, Month.JULY, 4)); centennials.add(LocalDate.of(1876, Month.JULY,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class....

    JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class. Print out the results after testing each of the methods in both of the classes and solving a simple problem with them. Task 1 – ArrayList Class Create an ArrayList class. This is a class that uses an internal array, but manipulates the array so that the array can be dynamically changed. This class should contain a default and overloaded constructor, where the default...

  • Create a new project in BlueJ and name it LastName-lab8-appstore, e.g., Smith-lab8-appstore. If your App class from Lab 4 is fully functional, copy it into the project. (You can drag a file from File...

    Create a new project in BlueJ and name it LastName-lab8-appstore, e.g., Smith-lab8-appstore. If your App class from Lab 4 is fully functional, copy it into the project. (You can drag a file from File Explorer onto the BlueJ project window.) Otherwise, use the instructor's App class: Create a new class using the "New Class..." button and name it App. Open the App class to edit the source code. Select and delete all the source code so that the file is...

  • Comparing the insertion and removing performance between ALPQueue with HeapPQueue. Requirements: ...

    Comparing the insertion and removing performance between ALPQueue with HeapPQueue. Requirements: 1/ Task1: implement a concrete ALPQueue class (an ArrayList based priority queue) that extends the AbstractPQueue discussed in the class, along with PQueue.java, ArrayList.java, List.java, PQEntry.java , EntryComparitor.java, and OutOfRangeException.java given in the class (any other implementation of above classes that are not compatible with List interface and AbstractPQueue class will not receive any credit). 2/ Task2: implement a concrete HeapPQueue class (a Heap based priority queue) that extends...

  • Comparing the insertion and removing performance between ALPQueue with HeapPQueue. Requirements: 1/ Task1: implement a concrete...

    Comparing the insertion and removing performance between ALPQueue with HeapPQueue. Requirements: 1/ Task1: implement a concrete ALPQueue class (an ArrayList based priority queue) that extends the AbstractPQueue discussed in the class, along with PQueue.java, ArrayList.java, List.java, PQEntry.java , EntryComparitor.java, and OutOfRangeException.java given in the class (any other implementation of above classes that are not compatible with List interface and AbstractPQueue class will not receive any credit). 2/ Task2: implement a concrete HeapPQueue class (a Heap based priority queue) that extends...

  • 10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated...

    10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated sludge operation that adversely affect effluent quality with origins in the engineering, hydraulic and microbiological components of the process. The real "heart" of the activated sludge system is the development and maintenance of a mixed microbial culture (activated sludge) that treats wastewater and which can be managed. One definition of a wastewater treatment plant operator is a "bug farmer", one who controls the aeration...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT