- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to find duplicate characters in a String?
Following is a Java example which deletes duplicate elements from a given string.
Example
import java.util.Arrays; import org.apache.commons.lang3.ArrayUtils; public class DuplicateSample { public static void main(String args[]){ String str = "malayalam"; char[] myArray = str.toCharArray(); for(int i=0; i<myArray.length-1; i++){ for (int j=i+1; j<myArray.length; j++){ if(myArray[i] == myArray[j]){ myArray = ArrayUtils.remove(myArray, j); } } } System.out.println("String value after deleting the duplicate values :"+Arrays.toString(myArray)); } }
Output
String value after deleting the duplicate values :[m, a, l, y]
- Related Articles
- Java program to find all duplicate characters in a string
- Java Program to Find the Duplicate Characters in a String
- Python program to find all duplicate characters in a string
- Java program to delete duplicate characters from a given String
- Golang program to find the duplicate characters in the string
- Program to find string after removing consecutive duplicate characters in Python
- Program to find string after deleting k consecutive duplicate characters in python
- C# Program to remove duplicate characters from String
- Program to remove duplicate characters from a given string in Python
- Find All Duplicate Characters from a String using Python
- How to print duplicate characters in a String using C#?
- Python Program to find mirror characters in a string
- Program to find cost to remove consecutive duplicate characters with costs in C++?
- Java program to check order of characters in string
- Java program to convert a list of characters into a string

Advertisements