Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

String remove duplicate in java

String str1 = "ABCDABCD";
String result1 = "";

for (int a = 0; a <= str1.length()-1; a++) {
if (result1.contains("" + str1.charAt(a))) { 
// charAt methodda you provide index number ve sana character olarak donuyor,
// If the string result does not contains str.CharAt(i), 
// then we concate it to the result. if it does we will not
   continue;
}
result1 += str1.charAt(a);
}
System.out.println(result1);
Comment

String remove duplicate method in java

public static void main(String[] args) {

        String result = removeDup("AAABBBCCC");
        System.out.println(result); // ABC

public static  String  removeDup( String  str) {
        String result = "";
        for (int i = 0; i < str.length(); i++)
            if (!result.contains("" + str.charAt(i)))
                result += "" + str.charAt(i);
        return result;
    }
}
Comment

java program to remove duplicate words in a string

String fullString = "lol lol";
String[] words = fullString.split("W+");
StringBuilder stringBuilder = new StringBuilder();
Set<String> wordsHashSet = new HashSet<>();

for (String word : words) {
    if (wordsHashSet.contains(word.toLowerCase())) continue;
    wordsHashSet.add(word.toLowerCase());
    stringBuilder.append(word).append(" ");
}
String nonDuplicateString = stringBuilder.toString().trim();
Comment

remove duplicates from string in java

int i,j;
StringBuffer str=new StringBuffer();
Scanner in = new Scanner(System.in);
System.out.print("Enter string: ");
str.append(in.nextLine());

for (i=0;i<str.length()-1;i++){
    for (j=i+1;j<str.length();j++){
        if (str.charAt(i)==str.charAt(j))
            str.deleteCharAt(j);
    }
}
System.out.println("Removed non-unique symbols: " + str);
Comment

PREVIOUS NEXT
Code Example
Java :: dictionary in java 
Java :: mono command to compile C# library code 
Java :: pre increment and post increments java 
Java :: get last string separated by / 
Java :: @override java example 
Java :: arraylist to linkedlist java 
Java :: check each character in a string java 
Java :: How to get the nth Fibonacci number code in Java using recursion 
Java :: read wss endpoint java 
Java :: java repeat method 
Java :: richest customer wealth 
Java :: java int array to integer arraylist 
Java :: fixed length array powershell PSv5+ 
Java :: class declaration in java 
Java :: What is the way to use profiles to configure the environment-specific configuration with Spring Boot? 
Java :: how to compare strings java 
Java :: java actionevent 
Java :: java.lang.NullPointerException 
Java :: android dialogfragment fullscreen stack overflow 
Java :: how to use ListIterator in java 
Java :: java newinstance alternative 
Java :: destory fragment 
Java :: declare generic set java 
Java :: switch statement java 
Java :: java print method 
Java :: variables inside strings kotlin 
Java :: Java get integer color from rgb 
Java :: multiple inheritance using interface in java 
Java :: Java How to use Queue? 
Java :: gui open event spigot 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =