Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java remove duplicates

import java.util.*;

public class RemoveDuplicatesFromArrayList {

    public static void main(String[] args) {
        List<Integer> numbers = Arrays.asList(1,2,2,2,3,5);

        System.out.println(numbers);

        Set<Integer> hashSet = new LinkedHashSet(numbers);
        ArrayList<Integer> removedDuplicates = new ArrayList(hashSet);

        System.out.println(removedDuplicates);
    }
}
Comment

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 remove duplicates

public static <T> ArrayList<T> removeDuplicates(ArrayList<T> list){
  Set<T> set = new LinkedHashSet<>(list);
  return new ArrayList<T>(set);
}
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

remove duplicate string collection in java

String str2 = "ABABABCDEF";// ABCDEF
        String[] arr2 = str2.split("");
str2 = new LinkedHashSet<>(Arrays.asList(arr2)).toString().replace(", ", "");
        System.out.println(str2); // ABCDEF
Comment

array remove duplicate in java

List<Integer>numbers = Arrays.asList(1,2,2,2,3,5); // [1, 2, 3, 5]
System.out.println(numbers);

Set<Integer> hashSet = new LinkedHashSet(numbers);
ArrayList<Integer> removedDuplicates = new ArrayList(hashSet);
System.out.println(removedDuplicates); // [1, 2, 3, 5]
Comment

PREVIOUS NEXT
Code Example
Java :: how to find prime numbers in java 
Java :: java.lang.arrayindexoutofboundsexception: index 3 out of bounds for length 3 
Java :: java fahrenheit to celsius 
Java :: Android Bitmap to Base64 String 
Java :: reverse a string in java 
Java :: check stack empty java 
Java :: tomcat 9 default username and password 
Java :: how to give square in java 
Java :: android java shared preferences remove key 
Java :: java list of arrays 
Java :: HOW TO PARSE a string into a number in java 
Java :: java multiple catch blocks 
Java :: for and while loops java 
Java :: java list to array 
Java :: java initialize class 
Java :: linear search algorithm java 
Java :: array of number arrays java 
Java :: sorting list in java 
Java :: java program for try catch finally 
Java :: in java how to compare two strings 
Java :: java variable declaration 
Java :: sort a list with custom comparator java 
Java :: jdk path 
Java :: hashmap get value by key java 
Java :: java node class 
Java :: équivalent setTimeInterval java 
Java :: regular expression java 
Java :: long to int java 
Java :: Java Create an InputStream 
Java :: variables inside strings kotlin 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =