Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

string to array iteration

import java.io.CharConversionException;
import java.util.ArrayList;
 
public class FindDuplicates {
 
    public static void main(String[] args) {
        String inputString = "My name is Guarav Kukade!";
 
        printDuplicates(inputString);
    }
 
    public static void printDuplicates(String inputString) {
        // count
        int count = 0;
 
        // a temp list of ch for which we have already printed the count
        ArrayList<Character> charList = new ArrayList<>();
 
        for (int i = 0; i < inputString.length(); i++) {
 
            char ch = inputString.charAt(i);
 
            // count the number of occurrences of the char ch in inputString
            for (int j = 0; j < inputString.length(); j++) {
                if (inputString.charAt(j) != ch) {
                    continue;
                }
                count++;
 
            }
 
            // check if we have already printed for ch
            if (!charList.contains(ch)) {
                // check if count is more than 1 i.e. duplicate and char should not be space
                if (count > 1 && ch != ' ') {
 
                    System.out.println("Char: " + ch + ", Count: " + count + " times.");
                    charList.add(ch);
                }
            }
 
            // set counter to zero for next ch
            count = 0;
        }
    }
 
}
Comment

how to saperate string to array

       Scanner in=new Scanner(System.in);
		String input=in.nextLine();
		String[] word=input.split(" ");
Comment

PREVIOUS NEXT
Code Example
Java :: java @override 
Java :: java final class 
Java :: java deserialize json object 
Java :: java sort array int 
Java :: search in 2d matrix 
Java :: calling a method in java 
Java :: Exception in Application start method java.lang.reflect.InvocationTargetException 
Java :: java format double no decimal places 
Java :: code to get date and time in android 
Java :: x = x + y; in java 
Java :: spring jpa query with union all 
Java :: Java Scanner nextDouble() 
Java :: ticket sales java program 
Java :: getUssd() kotlin 
Sql :: foreign key set 0 
Sql :: oracle change nls_date_format permanently 
Sql :: alter user mysql native password 
Sql :: update sql server from another table 
Sql :: kill mysql processlist in whose time more than 200 
Sql :: return names of columns in table sql 
Sql :: too many connections mysql 
Sql :: UseSqlServer no definition 
Sql :: sql query to get column names and data types in sql server 
Sql :: mysql add column if not exists 
Sql :: sql server list table sizes 
Sql :: mysql version check cmd 
Sql :: mysql last day of next month 
Sql :: oracle first day of last year 
Sql :: postgresql convert text to float 
Sql :: generate c# class from sql server table 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =