Make Selenium Easy

Frequently Asked Java Program 08: Program to find occurrence of individual characters in a given string.

Hello Folks,

As part of Frequently Asked Java Programs In Interviews For Freshers And Experienced, in this post we will learn to develop a java program to find out occurrence of individual characters in a given string.

Logic:

  1. To get input from user, we will use Scanner class.
  2. We will use Map interface concept here which deals in key-value pair.
  3. We will convert given string in to a char array.
  4. We will iterate char array index by index and will add in to Map if char does not exist already. If it exists we will increase value by one.

Java Program:-

Output:

Please provide a string to get count of characters:
Amod Mahajan
White space = 1
a = 4
d = 1
h = 1
j = 1
m = 2
n = 1
o = 1
Duplicate characters are:
a
m

======================================================================

Please provide a string to get count of characters:
Make Selenium Easy
White space = 2
a = 2
s = 2
e = 4
u = 1
i = 1
y = 1
k = 1
l = 1
m = 2
n = 1
Duplicate characters are:
a
s
e
m

If you have nay doubt or suggestions feel free to comment.
If you like my posts, please like, comment, share and subscribe.
#HappyCoding

Table of Contents

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

5 thoughts on “Frequently Asked Java Program 08: Program to find occurrence of individual characters in a given string.

  1. Longest pallindromic Substring ? Program can you pls share bro ?

    Ex : aabbracecardadmom

    in the above ex longest pallindromic substring is racecar.

    Can you pls share the code for that bro ? It will be helpful thanks.

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.