Comparing two list and removing duplicate elements

March 08, 2011 by Sandeep Bhardwaj | Tags:


Comparing two list and removing duplicate elements.

import java.util.ArrayList;
import java.util.List;

public class CheckList
{

 public static void main(String[] args)
 {

  List<string> a = new ArrayList<string>();
  a.add("a");
  a.add("b");

  List<string> b = new ArrayList<string>();
  b.add("c");
  b.add("a");
  b.add("d");
  b.add("f");

  b.removeAll(a);

  for (String str : b)
  {
   System.out.println(str);
  }
 }
}