This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes basic array-list method help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "basic array-list method help" Watch "basic array-list method help" New topic
Author

basic array-list method help

Kevin Schweitz
Greenhorn

Joined: May 17, 2011
Posts: 1
Hello all and thanks for the forum. I am trying to understand some basics for a class I am taking. I need to add a boolean method contains to my class called IntList which already has a bunch of other methods in it I created. All the method needs to do is return true if the parameter I am adding is already in my list and false if it isnt. I am passing in a list of integers from a file that is being scanned in to my test driver eventually if that helps. Not looking for an answer directly just someone to help me lay out the method. My book uses a while statement but in looking online I have found bits of pieces of if/else statements that are supposed to work as well.

Keep in mind I am barely learning the basics so basic level explanations would help me a lot. I am guessing but I am comparing ints not strings so I dont think I have to use compareto? Also I after I figure out what type of statement to write I need to look at my objects and values and figure where they go in the statement.
Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 557
The API is especially helpful to find answers to questions like this. The ArrayList API is here. Looking through the listed methods, you may find one that will help. For example, you may be able to use ArrayList.contains() to determine if the object you're testing for is contained in the subject ArrayList. contains() returns a boolean, so you may be able to use that result as the return from your method. Then again, if a method already exists that does what you want, why write a new one?


Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: basic array-list method help
 
Similar Threads
Query on arraylist
Final Semester of School Schedule
Using Jenny with Postgres...is there a mechanism to set the schema being used?
Ordered List
Need help finding assignments