Need a java ArrayList Interface class without using the built-in ArrayList class
ID: 3758029 • Letter: N
Question
Need a java ArrayList Interface class without using the built-in ArrayList class! Use the methods defined below and use the driver that is provided. If new methods are needed to complete the class than it's ok to add them!
Methods:
• void insert( Object, int index ) // Adds object ay the specified index
• Object remove(int index) // Remove and return the object at the specified index
• int size()
• String toString()
• boolean isEmpty()
• int indexOf(Object) // Returns -1 if not found
• boolean equals(Object) // Compares sizes and elements in the data structure
• Object get(int index) // Returns the object at index specified.
Driver:
public class ArrayListDriver {
public static void main( String[] args ) {
ArrayList a = new ArrayList();
a.insert( 'B', 0 );
a.insert( 'a', 0 );
a.insert( 't', 1 );
System.out.println( a.toString() );
while( a.isEmpty() == false ) {
System.out.println(a.remove( 0 ) );
}
}
}
Explanation / Answer
public class ArrayListDriver {
public static void main( String[] args ) {
ArrayList a = new ArrayList();
a.insert( 'B', 0 );
a.insert( 'a', 0 );
a.insert( 't', 1 );
System.out.println( a.toString() );
while( a.isEmpty() == false ) {
System.out.println(a.remove( 0 ) );
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.