Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ArrayList.contains() method Vs if/else

807580Dec 31 2009 — edited Dec 31 2009
sample.java

public sample {

public checkMethod(short val) {

// is the below comparison using if/else is best to use
short val1 = 1000;
short val2 = 2000;
short val3 = 3000;

if( val == val1 || val == val2 || val == val3) {
// some statements
}

// or Arraylist.contains best to use

Arraylist lst = new Arraylist();
lst.add(1000);
lst.add(2000);
lst.add(3000);

if(lst.contains(val)) {
// some stmts
}
}

please let me know which is best to use Arraylist.contains() or if/else.

Regards,
Subha



}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 28 2010
Added on Dec 31 2009
9 comments
661 views