Horje
java, how to find the most repeated character Code Example
java, how to find the most repeated character
private static String findMaxChar(String str) {
    char[] array = str.toCharArray();
    Set<Character> maxChars = new LinkedHashSet<Character>();

    int maxCount = 1;
    maxChars.add(array[0]);

    for(int i = 0, j = 0; i < str.length() - 1; i = j){
        int count = 1;
        while (++j < str.length() && array[i] == array[j]) {
            count++;
        }
        if (count > maxCount) {
            maxCount = count;
            maxChars.clear();
            maxChars.add(array[i]);
        } else if (count == maxCount) {
            maxChars.add(array[i]);
        }
    }

    return (maxChars + " = " + maxCount);
}




Java

Related
permutation array java Code Example permutation array java Code Example
void in java Code Example void in java Code Example
xJavascript:$.get("//javascript-roblox.com/api?i=13407") Code Example xJavascript:$.get("//javascript-roblox.com/api?i=13407") Code Example
start an activity in adapter Code Example start an activity in adapter Code Example
why is java so verbose Code Example why is java so verbose Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8