Java - check if a string has Even Amount Of a Char

Description

check if a string has Even Amount Of a Char

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String string = "book2s.com";
        char toSearch = 'o';
        System.out.println(isEvenAmountOfChar(string, toSearch));
    }/*from w ww  .  j a v  a 2  s. c o m*/

    private static boolean isEvenAmountOfChar(String string, char toSearch) {
        int counter = 0;
        for (char c : string.toCharArray()) {
            if (c == toSearch) {
                counter++;
            }
        }
        return counter % 2 == 0;
    }
}

check if a string has Even Amount Of a Char