How do I count the number of occurrences of a char in a String?

Posted by Bart on Stack Overflow See other posts from Stack Overflow or by Bart
Published on 2008-11-09T14:07:09Z Indexed on 2010/05/04 0:48 UTC
Read the original article Hit count: 252

I have the string

a.b.c.d

I want to count the occurrences of '.' in an idiomatic way, preferably a one-liner.

(Previously I had expressed this constraint as "without a loop", in case you're wondering why everyone's trying to answer without using a loop).

© Stack Overflow or respective owner

Related posts about java

Related posts about string-manipulation