This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 36452
    
  15
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: 7014
    
  16

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?
Artlicles by Winston can be found here
John Valiant
Greenhorn

Joined: Mar 01, 2012
Posts: 26
Thankc guys
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: startsWith
 
Similar Threads
Java String pool
how to sovle these two errors~~~help~~~
How String Can Be A Reference Variable...
blackberry pearl 8100
retreiving the session attribute value from anoher Action class