Question
import java.util.AbstractList; import java.util.List; import java.util.RandomAccess; import java.lang.RuntimeException; import java.util.Arrays; public class Vector extends AbstractList implements List , RandomAccess { protected Object[] data; protected int
import java.util.AbstractList; import java.util.List; import java.util.RandomAccess; import java.lang.RuntimeException; import java.util.Arrays;
public class Vector
public int size() { return size; } private void rangeCheck(int index) { if (index < 0 || index >= size) throw new IndexOutOfBoundsException(""); } @SuppressWarnings("unchecked") private E data(int index) { return (E) data[index]; } private void grow() { int newCapacity = data.length*2; data = Arrays.copyOf(data, newCapacity); } public Vector() { this(10); } public Vector(int initialCapacity) { data = new Object[initialCapacity]; size = 0; } public E get(int index) { rangeCheck(index); return data(index); } public E set(int index, E element) { rangeCheck(index); E oldValue = data(index); data[index] = element; return oldValue; } public boolean add(E element) { if (size == data.length) grow(); data[size++] = element; return true; } public void add(int index, E element) { // Add element at index. } public E remove(int index) {
// Remove the element at index. Make sure there are no gaps // Return the removed element } public int indexOf(Object o) {
// Returns the index of the first occurrence of the specified element // in this list, or -1 if this list does not contain the element. } public static void main(String[] args) { Vector
for (Integer i = 0; i < 10; i++) { intlist.add(i); }
System.out.println(intlist.indexOf(7)); System.out.println(intlist.indexOf("seven")); } }
PLEASE EDIT THIS CODE IN THE COMMENTS OF LAST 3 METHODS. COMMENTS TELL YOU WHAT TO DO. IT'S IN JAVA PROGRAMMING LANGUAGE.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started