Two Laptop Bag*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String.endsWith() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String.endsWith()" Watch "String.endsWith()" New topic
Author

String.endsWith()

umang bhartia
Ranch Hand

Joined: Sep 29, 2000
Posts: 60
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

Joined: Dec 18, 2000
Posts: 16
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String.endsWith()
 
Similar Threads
String question
Problem with String
String handling
String problem
toUpperCase() method returns a new String or not?