Find parts that are equal of 2 Strings in java

1

I would like to know if there is any way to compare 2 Strings in Java in such a way that they search not if they are equal, but if they do have equal parts and concatenate them without repeating the common parts.

Example:

Dice Strings as:  conf  onfi  nfid

The program returns me: confid

Thanks in advance.

    
asked by Yesid Bejarano Camacho 05.12.2017 в 23:15
source

1 answer

1

I think your statement has an error, the answer should be: onfid, otherwise you are organizing the appearance of characters in order without repetition, for example:

     String result = "";

     String test = "conf onfi nfid";

     for(int i = 0; i < test.length(); i++) {

         if (-1 == result.indexOf(test.charAt(i)) && test.charAt(i) != ' '){
             result += test.charAt(i);
         }
     }
     System.out.println(result); 
    
answered by 31.03.2018 в 01:26