<p>I have the string </p>

<pre><code>a.b.c.d
</code></pre>

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

<p>(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).</p>

Sooner or later,
something
has to loop. It's far simpler for you to write the (very simple) loop than to use something like
```
split
```
which is much more powerful than you need.
By all means encapsulate the loop in a separate method, e.g.
```
```
public static int countOccurrences(String haystack, char needle)
{
    int count = 0;
    for (int i=0; i < haystack.length(); i++)
    {
        if (haystack.charAt(i) == needle)
        {
             count++;
        }
    }
    return count;
}
```
```
Then you don't need have the loop in your main code - but the loop has to be there somewhere.