Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove specific value from string array in java? [duplicate]

Tags:

java

Possible Duplicate:
Removing an element from an Array (Java)

How to remove specific String array value for example

String[] str_array = {"item1","item2","item3"};

i want to remove "item2" from str_array pls help me i want output like

String[] str_array = {"item1","item3"};

like image 218
Vicky Avatar asked Oct 10 '12 05:10

Vicky


1 Answers

I would do it as follows:

String[] str_array = {"item1","item2","item3"};
List<String> list = new ArrayList<String>(Arrays.asList(str_array));
list.remove("item2");
str_array = list.toArray(new String[0]);
like image 141
Vikdor Avatar answered Oct 02 '22 19:10

Vikdor