Hi , Can someone please explain what is going on here Q#1 if( "String".endsWith("")) Sytem.out.println("True"); else System.out.println("False"); The code produces �True� Q#2 if( "String".startsWith("")) Sytem.out.println("True"); else System.out.println("False"); The code produces �True � I really don�t have any idea of output ?( why �True�?) Regards vivek
Hi Vivek, I think the result is correct. Just compile this code and see. class javaprog { public static void main(String [] ag) { //blank string if("String".endsWith(" ")) System.out.println("True"); else System.out.println("False"); } }
Here is a documented explanation from String API: startsWith: ... Note also that true will be returned if the argument is an empty string ... endsWith: ... Note that the result will be true if the argument is the empty string ...