 <p>I tested the following methods for 10M strings to count "," symbol.</p> <pre><code>// split a string by "," public static int nof1(String s) { int n = 0; if (s.indexOf(',') &gt; -1) n = s.split(",").length - 1; return n; } // end method nof1 // count "," using char[] public static int nof2(String s) { char[] C = s.toCharArray(); int n = 0; for (char c : C) { if (c == ',') n++; } // end for c return n; } // end method nof2 // replace "," and calculate difference in length public static int nof3(String s) { String s2 = s.replaceAll(",", ""); return s.length() - s2.length(); } // end method nof3 // count "," using charAt public static int nof4(String s) { int n = 0; for(int i = 0; i &lt; s.length(); i++) { if (',' == s.charAt(i) ) n++; } // end for i return n; } // end method nof4 // count "," using Pattern public static int nof5(String s) { // Pattern pattern = Pattern.compile(","); // compiled outside the method Matcher matcher = pattern.matcher(s); int n = 0; while (matcher.find() ) { n++; } return n; } // end method nof5 </code></pre> <p>The results:</p> <pre><code>nof1: 4538 ms nof2: 474 ms nof3: 4357 ms nof4: 357 ms nof5: 1780 ms </code></pre> <p>So, charAt is the fastest one. BTW, <code>grep -o ',' | wc -l</code> took 7402 ms.</p>