-7

I have array of strings like {item1,item2,item3,...,itemN}. I want to delete specific element from array. How can i do? Simplest way..

String s="How to delete items from list";

String[] result = s.split("\\s");

Now, I want to remove "delete" and "items" from array "result".

Goku
  • 9,102
  • 8
  • 50
  • 81

3 Answers3

1

Use a List<String> as below.

            List<String> myList = Arrays.asList(new LinkedList<String>(Arrays.asList(arrayname));
);
                    myList.remove(index);
Fathima km
  • 2,539
  • 3
  • 18
  • 26
0

Deletion in Array is not possible. You can initialize the position with null value but size will not be reduced.

String s="How to delete items from list";
String[] result = s.split("\s");      
result[2] = null;
KeLiuyue
  • 8,149
  • 4
  • 25
  • 42
0
List<String> arr = new LinkedList<String>(Arrays.asList(result));
arr.remove(2);
arr.remove(3);

System.out.println(arr.toArray(new String[0]));