Questions
I am implementing a generic List class and not getting the expected output. My current output...

I am implementing a generic List class and not getting the expected output.

My current output is: [0, 1, null]

Expected Output in a separate test class:

List list = new SparseList<>(); 
list.add("0");
list.add("1");
list.add(4, "4");

will result in the following list of size 5: [0, 1, null, null, 4].

list.add(3, "Three");

will result in the following list of size 6: [0, 1, null, Three, null, 4].

list.set(3, "Three");

is going to produce a list of size 5 (unchanged): [0, 1, null, Three, 4].

When removing an element from the list above, via list.remove(1); the result should be the following list of size 4: [0, null, Three, 4]

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class SparseList<E> implements List<E>{
    private int endIndex = 0;
    
    private HashMap<Integer,E> list;
    
    public SparseList() {
        list = new HashMap<>();
    }
    
    public SparseList(E[] arr) {
        list = new HashMap<>();
        for(int i = 0; i <arr.length; i++) {
            list.put(i, arr[i]);
        }
        endIndex = arr.length - 1;
    }
    
    @Override
    public boolean add(E e) {
        list.put(endIndex, e);
        endIndex++;
        return true;
    }
    
    @Override
    public void add(int index, E element) {
        list.put(index, element);
    }
    
    @Override
    public E remove(int index) {
        return list.remove(index);
    }
    
    @Override
    public E get(int index) {
        return list.get(index);
    }
    
    @Override
    public E set(int index, E element) {
        E previous = list.get(index);
        list.put(index, element);
        return previous;
    }
    
    @Override
    public int size() {
        return endIndex + 1;
    }

    @Override
    public void clear() {
        list.clear();
        
    }
    
    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public String toString() {
        String s = "";
        for(int i = 0; i < list.size(); i++) {
            if(list.get(i) == null) {
                s += "null, ";
            }else {
            s += list.get(i).toString() + ", ";
        }
        }
        return "[" + s + "]";
    }

    @Override
    public boolean contains(Object o) {
        throw new UnsupportedOperationException();
    }

    @Override
    public Iterator<E> iterator() {
        throw new UnsupportedOperationException();
    }

    @Override
    public Object[] toArray() {
        throw new UnsupportedOperationException();
    }

    @Override
    public <T> T[] toArray(T[] a) {
        throw new UnsupportedOperationException();
    }


    @Override
    public boolean containsAll(Collection<?> c) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean addAll(Collection<? extends E> c) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean addAll(int index, Collection<? extends E> c) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean retainAll(Collection<?> c) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean remove(Object o) {
        throw new UnsupportedOperationException();
    }
    
    @Override
    public int indexOf(Object o) {
        throw new UnsupportedOperationException();
    }

    @Override
    public int lastIndexOf(Object o) {
        throw new UnsupportedOperationException();
    }

    @Override
    public ListIterator<E> listIterator() {
        throw new UnsupportedOperationException();
    }

    @Override
    public ListIterator<E> listIterator(int index) {
        throw new UnsupportedOperationException();
    }

    @Override
    public List<E> subList(int fromIndex, int toIndex) {
        throw new UnsupportedOperationException();
    }

}
8.4.3

In: Computer Science

What is pneumonia? What nursing interventions would you initiate for a patient with pneumonia? How would...

  1. What is pneumonia?
  2. What nursing interventions would you initiate for a patient with pneumonia?
  3. How would this impact their daily living?
  4. List some focus points for patient teaching.
  5. List 5 things for this patient that you would want to know in morning report.

In: Nursing

Sort the list A[ ]={ 20, 13,4, 34, 5, 15, 90, 100, 75, 102, 112, 1}...

  1. Sort the list A[ ]={ 20, 13,4, 34, 5, 15, 90, 100, 75, 102, 112, 1} using Insertion Sort and determine the total number of comparisons made (do not count swaps)

b.Sort the list stated in 5a) but using Merge Sort

In: Computer Science

What is a bowel perforation? What is a hemicolectomy? What would be your priority assessment? What...

  1. What is a bowel perforation? What is a hemicolectomy?
  2. What would be your priority assessment?
  3. What are signs/symptoms of a pulmonary embolism?
  4. List 5 things for this patient that you would like to know in morning report.
  5. List some focus points for patient teaching.

In: Nursing

A rectangle has one side on the x-axis and two vertices on the curve y=2/(1+x^2) Find...

A rectangle has one side on the x-axis and two vertices on the curve y=2/(1+x^2) Find the vertices of the rectangle with maximum area. Enter your answer as a list of points (a, b) separated by semicolons. The order of the list does not matter.

In: Math

What money is money? Why it is necessary to have money? Among the two types of...

  1. What money is money?
  2. Why it is necessary to have money?
  3. Among the two types of money, which money is more important? Why?
  4. List two functions of Central Bank?
  5. List two ways the Central Bank of Kuwait can control money supply?

In: Economics

Choose four items from the following list. For the four items you choose, describe their roles...

Choose four items from the following list. For the four items you choose, describe their roles in skeletal muscle contraction.

List to choose from:

  • acetylcholine
  • actin
  • ATP
  • Ca2+
  • myosin
  • sarcomere
  • SR (sarcoplasmic reticulum)
  • T-tubules
  • troponin
  • tropomyosin

In: Biology

In the primary care setting, discuss how a problem list may be used, and discuss the...

  • In the primary care setting, discuss how a problem list may be used, and discuss the rationale for maintaining a medication list. Discuss the challenges and benefits of advanced practice registered nurses using social medial sites for professional purposes.Use at least one scholarly source

In: Nursing

Why do you think CSS is such a popular choice among web designers? List 3 advantages...

Why do you think CSS is such a popular choice among web designers? List 3 advantages in programming websites with CSS and support your assertions with examples. Also list 2 common challenges with CSS and how designers can overcome these problems.

In: Computer Science

need to know a,b,c A. list and describe in general terms the anatomy and function of...

need to know a,b,c

A. list and describe in general terms the anatomy and function of the organs and accessory organs of the digestive system.

B. identify: ingestion, propulsion, mechanical digestion, chemical digestion, absorption, defecation.

C. list the importance of vitamins and minerals in the diet

In: Anatomy and Physiology