Delete Particular Element of Array

  String[] str_array = {"item1","item2","item3"};
List list = new ArrayList(Arrays.asList(str_array));
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));
    

Comments

Popular posts from this blog

தட்டு வண்டியில் காளிக்கோயில் - சிறுகதை

பிரேமாவின் பெண் குழந்தை

தீபம் பிளக்ஸ்