Advertisement
cd62131

Duplicate

Mar 2nd, 2014
1,921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.51 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3.  
  4. public class Duplicate {
  5.   public static void main(String[] args) {
  6.     String[] ss = {"b", "b", "a", "a", "c", "c"};
  7.     List<String> ls = new ArrayList<String>();
  8.     for (int i = 0; i < ss.length; i++)
  9.       ls.add(ss[i]);
  10.     String prev = ls.iterator().next();
  11.     List<String> ret = new ArrayList<String>();
  12.     ret.add(prev);
  13.     for (String e: ls) {
  14.       if (!prev.equals(e)) ret.add(e);
  15.       prev = e;
  16.     }
  17.     System.out.println(ret);
  18.   }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement