Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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);
}
Comment

PREVIOUS NEXT
Code Example
Java :: a ^ b java 
Java :: springboot avoid generated security password: 
Java :: java coding standards for classes 
Java :: void setup 
Java :: javafx initialize 
Java :: how to find a string in a sentence in java 
Java :: 1.13. programacion orientada a objetos en java 
Java :: devotional meaning 
Java :: java gerüst 
Java :: spring mock Streamble of object 
Java :: matlab leslie eigenvalue java 
Java :: in java write a code that suppose the following input is supplied to the program: 9 Then, the output should be: 12096 (99+999+9999+999) 
Sql :: sql server search column name in all tables 
Sql :: postgresql stop all connections 
Sql :: convert utc to est sql 
Sql :: mysql get date difference in hours 
Sql :: check connections to database postgres 
Sql :: cambiar nombre tabla mysql 
Sql :: stpop start psql server 
Sql :: sql drop table if exists 
Sql :: mysql database stopped xampp mac 
Sql :: date today snowflake 
Sql :: rename column oracle 
Sql :: oracle search stored procedures for text 
Sql :: delete database mysql 
Sql :: if date is today mysql 
Sql :: how to rename table in sql 
Sql :: how to update date add hours in postgresql 
Sql :: mysql not supported auth mode 
Sql :: sql pick random row 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =