Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.The java.uti.ArrayList a.Create two instances of ArrayList. One instance must

ID: 3640690 • Letter: 1

Question

1.The java.uti.ArrayList

a.Create two instances of ArrayList. One instance must contain only String objects, one instance must contain Book objects.

b. Add a number of String and Book objects to each ArrayList instance.

c.Use each of the following ArrayList methods:

1)isEmpty

2)remove

3)size

4)add

5)iterator

6)listIterator

2. The java.util.LinkedList

a.create two instances of LinkedList. One instance must contain only String objects, one instance must contain only Book objects.

b.Add a number of String and Book objects to each LinkedList instance.

c.use each of the following LinkedList methods:

1)add

2)listIterator

3)iterator

Can anyone help me out please ?

Explanation / Answer

I am only providing anwer to ArrayList part, as the LinkedList one is exactly the same: public static void main(String[] args) { ArrayList books = new ArrayList(); ArrayList strings = new ArrayList(); Book b1 = new Book(100, false, "Lord of the Rings", 120); Book b2 = new Book(200, false, "Book 2", 34); Book b3 = new Book(300, true, "Title 3", 55); String s1= "Hello"; String s2 = "World"; String s3 = "ByeBye!"; System.out.println("Testing begins!"); // empty method System.out.println("Is books empty? " + books.isEmpty()); //add books.add(b1); books.add(b2); books.add(b3); strings.add(s1); strings.add(s2); strings.add(s3); System.out.println("Is strings empty? " + strings.isEmpty()); //size method - as a bonus System.out.println("Books size is now: " + books.size()); //remove strings.remove(0); System.out.println("Strings size is now: " + books.size()); Iterator it = books.iterator(); while(it.hasNext()){ System.out.println(it.next()); } ListIterator it2 = strings.listIterator(); String tmp1 = it2.next(); String tmp2 = it2.previous(); System.out.println("Next equals previous string? " + tmp1.equals(tmp2)); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote