Re: Simple syntax question
- From: Joshua Cranmer <Pidgeot18@xxxxxxxxxxxxxxx>
- Date: Fri, 29 Feb 2008 01:57:00 GMT
somebody wrote:
Is this the best we to conditionally do something if str is NOT equal to
one, two, three, or four, AND mystr is NOT equal to X? I can't seem to
find anything like a str.unequal. I want the if block to execute if str
equals "seven" and mystr equals "Y"
if ( !(str.equals("one")) && !(str.equals("two")) && !(str.equals("three")) && !(str.equals("four")) &&
(mystr.compareTo("X") != 0) )
{
Then do this...
Long, and not very pretty. Alternatively, you could use something like this:
List<String> strings = Arrays.asList("one", "two", "three", "four");
if (!strings.contains(str) && !mystr.equals("Y")) {
This is also has the benefit of being easier to expand and refactor.
--
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
.
- References:
- Simple syntax question
- From: somebody
- Simple syntax question
- Prev by Date: Re: Trouble using POST method with servlet
- Next by Date: Re: PreOrder Tree Traversal
- Previous by thread: Re: Simple syntax question
- Next by thread: Re: Simple syntax question
- Index(es):
Relevant Pages
|
|