Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create your own ArrayList class called MyArrayList. Your MyArrayList class will implement the interface called MyArrayListInterface. The MyArrayList will only be used for containing String

Create your own ArrayList class called MyArrayList. Your MyArrayList class will implement the interface called MyArrayListInterface. The MyArrayList will only be used for containing String objects.

You will need to research how a Java ArrayList works. MyArrayList should implement a hidden resizable String array. Your array should grow dynamically and ensures that there is always space to add elements. You should start out with a String array of size 10.

Use the Main class to test your MyArrayList methods.

Main.java

class Main { public static void main(String[] args) { MyArrayList list = new MyArrayList(); } }

MyArrayList.java

public class MyArrayList implements MyArrayListInterface {

}

MyArrayLisrInterface.java

public interface MyArrayListInterface {

/** * Returns the number of elements in this list. */ public int size();

/** * Returns true if this list contains no elements. */ public boolean isEmpty();

/** * Appends the specified String to the end of this list. * Returns true if successful */ public boolean add(String str);

/** * Inserts the specified String at the specified position in this list. * Throws IndexOutOfBoundsException if the index is out of range. */ public void add(int idx, String str);

/** * Returns the String at the specified position in this list. Throws * IndexOutOfBoundsException if the index is out of range. */ public String get(int idx);

/** * Replaces the String at the specified position in this list with the * specified String. */ public String set(int idx, String str);

/** * Removes and returns the String at the specified position in this list. */ public String remove(int idx);

/** * Removes the first occurrence of the specified String from this list, if * it is present. */ public boolean remove(String str);

/** * Returns the index of the first occurrence of the specified String in this * list, or -1 if this list does not contain the element. */ public int indexOf(String str);

/** * Returns true if this list contains the specified String. */ public boolean contains(String str);

/** * Returns an array containing all of the elements in this list in proper * sequence (from first to last element). The returned array will be "safe" * in that no references to it are maintained by this list. (In other words, * this method must allocate a new array). The caller is thus free to modify * the returned array. */ public String[] toArray(); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

More Books

Students also viewed these Programming questions

Question

Explain why a supply curve slopes upward.

Answered: 1 week ago