-6

I hope you are fine.

I am searching for a simple way to compare two Strings and print out the words which are unique between the two, for example I have :

String one = edittext1.getText().toString();
String two = editText2.getText().toString();

Then the output should be what is the words that exists in edittext1 and not exist in edittext2.

HishamKanon
  • 25
  • 1
  • 6
  • word by word are the same but what if it miss word or some words are different example of what i want https://text-compare.com/fr/ – HishamKanon Oct 22 '20 at 12:22
  • but not whole code you didn't even started ... And you didn't even provide what you need "the words that are differet" ... it means : "this is first text example" and "example test first is this" are the same ... and then you are show some website whitch works different – Selvin Oct 22 '20 at 12:25
  • this is what i neeeeeeeeeeeeeeeeeeed compare between two small strings !!!!!!!!!!!!!!!!! i don't need MainActivity.java i said i need to compare between two strings what is weird in that. – HishamKanon Oct 22 '20 at 12:29
  • you may use `String.compareTo` or `String.equals` to compare strings :D – Selvin Oct 22 '20 at 12:30
  • Does this answer your question? [How do I compare strings in Java?](https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Nitin Zadage Oct 22 '20 at 12:38

1 Answers1

-1

if it's only words you can split the strings to string[] that each cell will contain 1 word only and then compare those words. Goes as follows:

String one = "this is first text example";
String two = "this is next text example";
String[] oneVals = one.split("\\ ");
String[] twoVals = two.split("\\ ");
int i = oneVals.length;
if(oneVals.length != twoVals.length)
{
    // determine what to do
}
String wordsNotMatching = "";
for(int j=0; j<i; j++)
{
    if((!oneVals[j].equals(twoVals[j])))
        wordsNotMatching += oneVals[j] + " ";
}
// wordNotMatching will contain all different words.
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Dan Baruch
  • 1,063
  • 10
  • 19