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

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

PREVIOUS NEXT
Code Example
Java :: Execute method on load 
Java :: intellij run single java file 
Java :: Run the ls command in the terminal to see the uncompiled .java file 
Java :: how to scroll down chrome browser in selenium java 
Java :: Program to read base and power and then calculate result of that expression using recursion in java 
Java :: start/php2 
Java :: setBackgrounfTint color to relative layout from java file 
Java :: witch dependency is needed for "ArraysUtils" for the Import? 
Java :: adding new field in existing kibana index using spark java 
Java :: build cmake gradle 
Java :: how to return list in java 
Java :: break statement in Java switch...case 
Java :: bloomreach get node via id 
Java :: Second Activity not opening problem 
Java :: Could not find com.commercehub.gradle.plugin:gradle-avro-plugin:0.10.0. 
Java :: android java random fragment on create 
Java :: get material of block bukkit 
Java :: how to take input an array in java 
Java :: Determining what type of data the ArrayList will contain in java. 
Java :: What is sleep() method 
Java :: convert kotlin to java online editor 
Java :: display pop up window overlay permission in redmi android studio 
Java :: java classes and objects 
Java :: findview by id in android 
Java :: android list to string 
Java :: alert dialog not displayed android 
Java :: result set methods 
Java :: how to stop screen going off android studio 
Java :: button height is not increase in android studio 
Java :: como pegar o valor de um campo de texto swing 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =