Java : Brackets within the if condition

if ((one.option != two.option) && (one.side == two.side))

I need to check the followng Business Logic above

so i written this way


Is this correct ??

Assuming data[0] in place of one getData.value() in place of option shown in the top if condition .

I am concerned about the brackets inside the if condition


It's correct, but personally I wouldn't bother with the brackets in this particular case. I would, however, use more whitespace. I'd write that as:

if (data[0].getData.value() != data[1].getData.value()
    && data[0].getAction().value() == data[1].getAction().value())

If you really want the brackets, I'd write it as:

if ((data[0].getData.value() != data[1].getData.value())
    && (data[0].getAction().value() == data[1].getAction().value()))

I'd normally only include the brackets if I wanted to differentiate between, say,

if ((x && y) || z)


if (x && (y || z))

Of course, this is assuming that the values are ones which are appropriate to compare with == and !=. If they're strings or other objects, you should potentially be using equals instead.

Need Your Help

How do I test Action Bar's Action Items from Robolectric?

android unit-testing robolectric

Real quick, is there a way in the current Robolectric to verify the presence and visibility of an action item on the action bar? (I know this basically writing a unit test for a UI configuration de...

On my Google Maps when I zoom out beyond level 10 all my markers disappear

google-maps maps

My google maps work fine at a zoom level higher than 10, but if I zoom out my markers disappear. I cant see where the error is. Have tried using v3 and v2. Also changing from .png markers to .gif. ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.