“String hapus metode duplikat di java” Kode Jawaban

Java Hapus duplikat

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);
    }
}
Shy Snail

String hapus metode duplikat di 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;
    }
}
Ozzzy

Program Java untuk menghapus kata duplikat dalam 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();
VasteMonde

Java Hapus duplikat

public static <T> ArrayList<T> removeDuplicates(ArrayList<T> list){
  Set<T> set = new LinkedHashSet<>(list);
  return new ArrayList<T>(set);
}
Efton

array hapus duplikat di 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]
Ozzzy

Jawaban yang mirip dengan “String hapus metode duplikat di java”

Pertanyaan yang mirip dengan “String hapus metode duplikat di java”

Lebih banyak jawaban terkait untuk “String hapus metode duplikat di java” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya