0

what would be the least verbose way to remove one item by value from char[] core java 8 > ?

char[] c = new char[] {'a', 'b', 'c'}; 

I want remove 'b' for egz.

3
  • 1
    Does this answer your question? Removing an element from an Array (Java) Commented Apr 3, 2020 at 20:15
  • 1
    Arrays have fixed size so please describe result you expect. Should it be new array with size reduced by amount of matching elements like {'a', 'c'}, or maybe something else like array which instead of matching elements have some special values like # for instance {'a', '#', 'c'}? Commented Apr 3, 2020 at 20:18
  • thanks for idea, that might work in some cases - and easy.. but yea i was more of how to remove an item in the way that array size is reduced. Commented Apr 3, 2020 at 20:57

1 Answer 1

3

Not especially efficient, but certainly not verbose

char[] c = new char[] {'a', 'b', 'c'};
c = new String(c).replace("b","").toCharArray();
Sign up to request clarification or add additional context in comments.

4 Comments

getBytes() -> toCharArray()
nice! just thinking about case when there are two 'b' and I want to remove only one of them.. :/ but probably that would be a different question.
@domingo you can use regular expressions for what you are suggesting
thanks, that would work. thought I'm more in array thinking as I want to manipulate array of chars, in TS or JS that seemed less verbose, easier to find index and remove by it, Also Java Arrays.streams is not there for char array but is there for other primitives.. anyway it is easy to write code to find index, but than remove by that index.. System.arraycopy maybe... Anyways there is an apache utils for a reason, xexe.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.