fork(1) 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. String[] uniquewords = new String[0];
  14. for(int i = 0; i < words.length; i++) {
  15. String word = words[i];
  16. boolean unique = true;
  17. for(int j = 0; j < uniquewords.length; j++) {
  18. if( word.equals(uniquewords[j]) ) {
  19. unique = false;
  20. break;
  21. }
  22. }
  23. if( unique ) {
  24. String more[] = new String[uniquewords.length + 1];
  25. for(int j = 0; j < uniquewords.length; j++) {
  26. more[j] = uniquewords[j];
  27. }
  28. more[more.length - 1] = word;
  29. uniquewords = more;
  30. }
  31. }
  32. for(int i = 0; i < uniquewords.length; i++) {
  33. System.out.println(uniquewords[i]);
  34. }
  35. }
  36. }
Success #stdin #stdout 0.06s 32512KB
stdin
Standard input is empty
stdout
hello
i
am
norman