fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String[] words = new String[] {"hello", "hello", "i", "i", "am", "norman"};
  13. int from=0,to=0;
  14. while(from < words.length) {
  15. String word = words[from];
  16. boolean unique = true;
  17. for(int i = 0; i < to; i++) {
  18. if( word.equals(words[i]) ) {
  19. unique = false;
  20. break;
  21. }
  22. }
  23. if( unique ) {
  24. words[to] = word;
  25. to++;
  26. }
  27. from++;
  28. }
  29. for(int i = 0; i < to; i++) {
  30. System.out.println(words[i]);
  31. }
  32.  
  33. //String[] uniquewords = new String[to];
  34. //for(int i = 0; i < to; i++) {
  35. // uniquewords[i] = words[i];
  36. //}
  37. }
  38. }
Success #stdin #stdout 0.07s 32528KB
stdin
Standard input is empty
stdout
hello
i
am
norman