Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String.endsWith()

 
umang bhartia
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class end
{
public static void main(String[] args)
{
if("String".endsWith(""))
System.out.println("True");
else
System.out.println("False");
}
}
Output: True
Can any one explain how the output is true
 
Axl Rose
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
note that the method endsWith(""), takes actually an empty string, or a string that contains nothing, not a single character.
and if we compare it with what the java doc say about the method endsWith(String argument)in the String class:
"Note that the result will be true if the argument is the empty string or is equal to this String object as determined by the"
so the answer will be true.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic