Make Selenium Easy

Frequently Asked Java Program 30: Java Program to Find Distinct Characters In Given String

Hello Folks,

As part of Frequently Asked Java Programs In Interviews For Freshers And Experienced, in this post we will see a java program to Find Distinct Characters In Given String.

Problem Statement:

User input: Make Selenium Easy

Output: K L N I U Y

Problem Solution: 


  1. Convert input string in to same case either upper or lower.
  2. Replace all whitespace with empty space. 
  3. Take first char from given String.
  4. lastIndexOf(char c) method of String class gives the index of last occurrence of char in given string. If a character is not repeated in given string,  lastIndexOf should give zero as we took first char to check. If it is zero, print.
  5. To repeat step 3 and 4, we must need to replace already checked char from string with empty space.

Java Program:


Please enter the string to find distinct characters:
Make Selenium Easy
You entered: Make Selenium Easy

Run program for multiple inputs and let me know if it fails. Comment if you have better approach. If you like my posts please like, comment and share to reach it to maximum.


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.

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.