0

Let's think we have a list like this

int[] values = {1, 2, 3, 4, 5};

I want to delete an element of values by index. I mean, the programme will ask an index, if the input is 3, values' 4th index will be deleted.

I can't use ArrayLists 'cuz I'm writting a programme with 300 lines, and I don't want to convert all that Lists to ArrayList.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • You cannot remove an element from an array. You can either create a new array without that element or rather use `List` instead. – René Vogt Sep 03 '20 at 09:17
  • "Let's think we have a list like this" - that's not a list, it's an array. They're very different, and you can't resize an array after creation. You can create a *new* array, but that's not the same thing. Note that using `ArrayList` would also be a bad idea - non-generic collections are almost never as useful as the generic ones. You should use a `List` - and 300 lines is a pretty small-scale refactor, to be honest. – Jon Skeet Sep 03 '20 at 09:17
  • tnx guys I guess it will be hard to convert all arrays but I'll try.d – Demir Döküm Sep 03 '20 at 09:22

0 Answers0