How to compare two Strings in java without considering spaces? -
i have 1 example.
public class test { public static void main(string[] args) { string a="vijay kakade"; string b="vijay kakade"; if(a.equalsignorecase(b)){ system.out.println("yes"); }else{ system.out.println("no"); } } }
i need check these strings without considering spaces. how achieve this? how ignore spaces in strings when compare them?
you can try create new string replacing empty spaces.
if(a.replaceall("\\s+","").equalsignorecase(b.replaceall("\\s+",""))) { // take care of spaces tabs etc. }
then compare.
Comments
Post a Comment