This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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.
 
Consider Paul's rocket mass heater.
 
subject: String.endsWith()
 
Similar Threads
String problem
String handling
Problem with String
toUpperCase() method returns a new String or not?
String question