check if a string has Even Amount Of a Char
//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 a2 s .com 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