File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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: 38519
    
  23
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: 7718
    
  20

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