• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

startsWith

 
John Valiant
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



This doesnt seem to work.How can i use || with startsWith?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49813
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10508
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
John Valiant
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankc guys
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic