Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Program to remove duplicates in an ArrayList

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

public class ArrayDuplicate {
    public static void main(String args[]) {

List<Integer> num = new ArrayList<Integer>();
num.add(1);
num.add(2);
num.add(3);
num.add(4);
num.add(5);
num.add(6);
num.add(3);
num.add(4);
num.add(5);
num.add(6);

System.out.println("Your list of elements in ArrayList : " + num);
Set<Integer> primesWithoutDuplicates = new LinkedHashSet<Integer>(num);
num.clear();
num.addAll(primesWithoutDuplicates);
System.out.println("list of original numbers without duplication: " + num);

}
}
Comment

remove duplicates from arraylist in android

 ArrayList<Object> withDuplicateValues;
 HashSet<Object> withUniqueValue = new HashSet<>(withDuplicateValues);
 
 withDuplicateValues.clear();
 withDuplicateValues.addAll(withUniqueValue);
Comment

PREVIOUS NEXT
Code Example
Java :: parameterized constructor java 
Java :: json java 
Java :: limit decimals java 
Java :: control structures in java 
Java :: maths trivia in java 
Java :: syntax of the switch statement in Java 
Java :: java streams 
Java :: Java Nested and Inner Class 
Java :: java data structure 
Java :: java read fule get String 
Java :: comments java 
Java :: positive numbers in array 
Java :: java hex to rgb 
Java :: new int[] java 
Java :: java draw image 
Java :: singleton 
Java :: logcat android 
Java :: Find Length of String using length() 
Java :: mcq java 
Java :: android videoview not smooth for mp4 
Java :: calculate the area of two squares in java by using a method 
Java :: program Pr115_3; var k, n : integer; suma : real; begin readln(n); suma := 0; for k := 1 to n do suma := suma + 1 / sqr(2*k+1); writeln(suma); readln; end. 
Java :: Java Custom Annotations 
Java :: access char in string 
Java :: ex: java loop 
Java :: how to make bidirectional fromated binding 
Java :: java deserialize json array 
Java :: java arraylist max length 
Java :: how to implement seekbar for music in java 
Java :: ExpandableLayout in android 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =