Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6086801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:47:49+00:00 2026-05-23T11:47:49+00:00

I have implemented array list with arrays: public class ArrayIndexList<E> { private E[] A;

  • 0

I have implemented array list with arrays:

public class ArrayIndexList<E> {
    private E[] A;
    private int capacity = 5; // Initial Array Size
    private int size = 0;

    public ArrayIndexList() {
        A = (E[]) new Object[capacity];
    }

    public void add(int index, E element) {
        /* if array is full:
         * 1. double the array size
         * 2. copy elements to the new array */
        if (size == capacity) {
            capacity = capacity * 2;
            E[] B = (E[]) new Object[capacity];
            for (int i = 0;i < size;i++)
            B[i] = A[i];
            A = B;
        }

        // shift the elements up
        for (int i = size - 1;i >= index;i--)
            A[i + 1] = A[i];

        // add new element
        A[index] = element;
        size = size + 1;
    }

    public E remove(int index) {
        E temp = A[index];

        //shift elements down
        for (int i = index;i < size - 1;i++)
            A[i] = A[i + 1];
        size = size - 1;

        return temp;
    }
}

It is working, but compiler gives warning:

Type safety: Unchecked cast from Object[] to E[] ArrayIndexList.java

What’s wrong with the code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:47:50+00:00Added an answer on May 23, 2026 at 11:47 am

    The cast cannot be checked a runtime, therefore a warning is given. With
    an up to date compiler, you can suppress the warning using @SuppressWarnings("unchecked").

    was it helpful ?

    http://mindprod.com/jgloss/compileerrormessages.html#TYPESAFETYERASED

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have the following java bean: public class MyBean { private List<String> names
In my app I have an array List<Friends> friends =new ArrayList<Friends>(); where Friends is
I have three java types as defined below: Main.java: import java.util.Arrays; import java.util.List; public
I have implemented a python webserver. Each http request spawns a new thread. I
I have implemented VirtualPathProvider class so I can keep all my views in the
I have declared an ArrayList and DefaultListModel DefaultListModel model; List<AddFlight> Flights = new ArrayList<AddFlight>();
Inside public class IAmHere extends Activity implements LocationListener { i have @Override public void
I need to create a random array of int and have it sorted by
I have a routine public void SomeRoutine(List<IFormattable> list) { ... } I then try
I have the following backing bean: @ViewScoped @ManagedBean public class WeighFamilyBacking2 implements Serializable {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.