0

Can anyone of you help me overwrite something from my Spherocylinder array?

I've got this currently:

   public Spherocylinder deleteSpherocylinder(String labelIn)
   {
      Spherocylinder result = null;
      int index = 0;      

      for (int i = 0; i < elements; i++)
      {
         if (object[i].getLabel().equalsIgnoreCase(labelIn))
         {
            //My issue is with the line of code below, i know this is 
            //how i delete an element in an arraylist but i know want to 
            //delete it using an array.
            result = object.remove(i);
         }
      }

      return result;
   }

where (object) is the name of my Spherocylinder array and (elements) is an int I use which tells me how many elements i have in my array. This line of code is just one of my methods in my class, any help would be appreciated.

1 Answers1

0

You can't "remove" and element from an array. Arrays have a fixed length, so you can only overwrite the value in a cell.

What you might be looking for, is maybe overwriting the value you want to "remove" with say the last value or shifting all values by one (which is what ArrayList.remove() does.

Malt
  • 28,965
  • 9
  • 65
  • 105
  • Oh right I remember that now, could you please tell me exactly how i would overwrite the value based on my code. I've been working on this one method for hours but can't seem to get it, thanks. – Mitchel Santillan Oct 28 '17 at 16:51