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) {
  11. String[] a = {"teste1", "teste2", "teste1"};
  12. String[] b = new String[a.length];
  13. for(int i = 0; i < a.length; i++) {
  14. if(arrayNaoContemString(b, a[i])) {
  15. b[i] = a[i];
  16. }
  17. }
  18. for (String string : b) {
  19. System.out.println(string);
  20. }
  21. }
  22.  
  23. public static boolean arrayNaoContemString(String[] array, String string){
  24. for(String s : array){
  25. if (string.equals(s)){
  26. return false;
  27. }
  28. }
  29. return true;
  30. }
  31. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
teste1
teste2
null