Mike. J. Thompson wrote:Hi.
Don't use the == operator to compare Strings (or any Object references) for equality. It doesn't compare equality, but rather identity. It returns true only if both references are pointing to the same object, not if the objects contain the same data.
Instead, use:
Paweł Baczyński wrote:You could also use the switch statement.
I hadn't been here for fifteen years
Paweł Baczyński wrote:You could also use the switch statement.
I hadn't been here for fifteen years
I would suggest that learning a pre‑Java5 programming style might be harmful; you would learn Collections without generics and then have to unlearn it to learn generics.The Java™ Tutorials paged linked to wrote:Using Strings in switch Statements
In Java SE 7 and later
Campbell Ritchie wrote:
I would suggest that learning a pre‑Java5 programming style might be harmful; you would learn Collections without generics and then have to unlearn it to learn generics.The Java™ Tutorials paged linked to wrote:Using Strings in switch Statements
In Java SE 7 and later
I hadn't been here for fifteen years
Campbell Ritchie wrote:I didn't mean not to learn the history. There is a difference between learning programming and learning a language.
Wert thou to come to me to ask I instruct thee in the English tongue, wert thou grateful I taught thee thus?
I hadn't been here for fifteen years
Campbell Ritchie wrote:
I would suggest that learning a pre‑Java5 programming style might be harmful; you would learn Collections without generics and then have to unlearn it to learn generics.The Java™ Tutorials paged linked to wrote:Using Strings in switch Statements
In Java SE 7 and later
I hadn't been here for fifteen years
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |