-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".

0

3 Answers 3

1

Use a List<String> as below.

            List<String> myList = Arrays.asList(new LinkedList<String>(Arrays.asList(arrayname));
);
                    myList.remove(index);
Sign up to request clarification or add additional context in comments.

2 Comments

.UnsupportedOperationException
I have edited my code to avoid this exception
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;

2 Comments

any reason why answer is downvoted?
i want shift the place of array as well. Means at resutl[2] i want "from"
0
List<String> arr = new LinkedList<String>(Arrays.asList(result));
arr.remove(2);
arr.remove(3);

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.