I have an array of String in java like {"A", "B", "C"} and I want to shrink the array so the new should be like {"A", "B"}. I want to shrink it without using the new array or any pre define class methods or collection API. Just to correlate, In C language we can just simply put '\0' character which indicates the end of the string.
Asked
Active
Viewed 29 times
-1
-
2In Java, arrays are fixed in size. If you want to remove an element from an array, you must create a new array and copy the contents of the old array into the new one. – Jacob G. May 19 '20 at 18:58
-
Now, I get it we can't remove an element from an array in java but why? – TanishGupta May 20 '20 at 06:19
1 Answers
0
Array size can't be changed, but you could use linked lists or array lists instead. The access to elemnts with these is slower than with arrays but there is no limit for how many elements they can contain and it's faster to remove and move elements.

5pectr
- 1