List
list.remove("item2");
str_array = list.toArray(new String[0]);
System.out.println(Arrays.toString(str_array));
public static String[] removeItemFromArray(String[] input, String item) {
if (input == null) {
return null;
} else if (input.length <= 0) {
return input;
} else {
String[] output = new String[input.length - 1];
int count = 0;
for (String i : input) {
if (!i.equals(item)) {
output[count++] = i;
}
}
return output;
}
}
String[] strArr = new String[]{"google","microsoft","apple"};
final List list = new ArrayList();
Collections.addAll(list, strArr);
list.remove("apple");
strArr = list.toArray(new String[list.size()]);
System.out.println(Arrays.toString(strArr));
No comments:
Post a Comment