aspose file tools*
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
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: 39828
    
  28
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: 8218
    
  23

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: startsWith