Ciao ho due stringhe:Estrarre la differenza tra due stringhe in Java
String hear = "Hi My name is Deepak"
+ "\n"
+ "How are you ?"
+ "\n"
+ "\n"
+ "How is everyone";
String dear = "Hi My name is Deepak"
+ "\n"
+ "How are you ?"
+ "\n"
+ "Hey there \n"
+ "How is everyone";
voglio ottenere ciò che non è presente nella stringa di sentire che è "Hey There \ n". Ho trovato un metodo, ma non riesce per questo caso:
static String strDiffChop(String s1, String s2) {
if (s1.length() > s2.length()) {
return s1.substring(s2.length() - 1);
} else if (s2.length() > s1.length()) {
return s2.substring(s1.length() - 1);
} else {
return "";
}
}
Qualcuno può aiutare?
Penso che un altro approccio possa essere suddiviso Stringa basata sullo spazio e quindi loop su ogni elemento? – kosa
Sì Nambari, grazie. Questo è quello che ho fatto . –