how to replace multiple array elements. I know how to remove an array element but the thing is if I remove one element the index will decrease but I want keep the index number.
An array is not mutable... How do you remove an element so that the indeces of the array are changed? This would mean you're changing the length of the array? Maybe you mean an ArrayList? Then you could set the list element to null.
Thanks Tashi N for your response. I mananged to use "Collection.addAll" method and its working perfectly.
Assuming you were talking about an array: Replace an element the same way you add one. int a = new int; a = 4; a = 9; // replaced 4 with 9 For an arraylist, there's also a set(int, element) method. int being the index of the element you want to replace, and the element being what you are replacing it with.
Here is a code that replaces array element. https://code.sololearn.com/cQ5prF6zVujo/?ref=app