I have an array like this:
String n[] = {"google","microsoft","apple"};
What I want to do is to remove “apple”.
My problem is very basic,however,I searched the website and I found out that java doesn’t really support the deleting feature from an array.I also heard to use Java Utils, because it’s so simple to remove an item….I tried to find Java Utils on google, but almost all links are dead.
So finally…is there any way to remove a string from an array of string?
Even if I use an ArrayList I can’t find a method to generate a random item in it! For ex: in a normal array I generate a string like this:
String r = myAL[rgenerator.nextInt(myAL.length)];
In an arraylist it doesn’t work….maybe you know a solution…
Define “remove”.
Arrays are fixed length and can not be resized once created. You can set an element to
nullto remove an object reference;or
If you want a dynamically sized array where the object is actually removed and the list (array) size is adjusted accordingly, use an ArrayList<String>
or
Edit in response to OP’s edit to his question and comment below