-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
  • 8,341
  • 7
  • 43
  • 73

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,229
  • 3
  • 17
  • 25
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
  • 7,831
  • 4
  • 23
  • 39
0
List<String> arr = new LinkedList<String>(Arrays.asList(result));
arr.remove(2);
arr.remove(3);

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