Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes startsWith 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 » Java » Beginning Java
Bookmark "startsWith" Watch "startsWith" New topic
Author

startsWith

John Valiant
Greenhorn

Joined: Mar 01, 2012
Posts: 26



This doesnt seem to work.How can i use || with startsWith?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38062
    
  22
No, of course you can’t use || to separate two Strings; it only operates on booleans. (Booleans are un-boxed if you try to use them with ||.)
You would have to use s.startsWith("x") || s.startsWith("y") or similar.
I think you are going to want more “starting with” letters, so you might do well to learn about regular expressions; you could use a regex which permits starting with any of a large selection of characters.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7552
    
  18

John Valiant wrote:This doesnt seem to work.How can i use || with startsWith?

Sounds to me like these are types, in which case you probably want to be defining classes for them rather than checking initial characters.

Strings make poor substitutes for other types.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
John Valiant
Greenhorn

Joined: Mar 01, 2012
Posts: 26
Thankc guys
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: startsWith
 
Similar Threads
retreiving the session attribute value from anoher Action class
blackberry pearl 8100
how to sovle these two errors~~~help~~~
How String Can Be A Reference Variable...
Java String pool