• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

basic array-list method help

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
It's just a flesh wound! Or a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic