Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


accessing attributes and methods in ArrayList of objects??

finniefinnie Member Posts: 1

I need help on a small database, with video clips and corresponding competitors, i'll need to be access both individual clips by index, and the clips of a competitor for sorting etc.

So far i can add Competitor objects to an ArrayList within my main client class, but i'm having trouble accessing their attributes or using methods of the Competitor class

This is my (also has standard .set .get methods for each attribute)
public class Competitor {

private String surname;
private String givenname;
private ArrayList ClipList = new ArrayList();

// Competitor object constructor
public Competitor(String surname, String givenname, ArrayList ClipList) {
this.surname = surname;
this.givenname = givenname;
this.ClipList = ClipList;
Heres a method out of my main client class (which contains ClipList and CompetitorList) The end goal is to have a CompetitorList, and each Competitor will have an ArrayList of Clips he/she owns. There will also be a main ClipList of the same Clips so i can access any Clip by its index. does this sound right?
This method has both ClipList and CompetitorList passed to it from the main method, it calls other methods to read input and add a new Competitor to CompetitorList. Is this the best/right way to alter the lists?
public static void clipAddOption(ArrayList ClipList, ArrayList CompetitorList) {

System.out.println("clipAddOption stub");

boolean addCompetitor = question("Do you need to add a new competitor?");

if (addCompetitor) {

This seems to work fine, but how on earth to i access the elements of CompetitorList. Do i have modify/access the ArrayLists only from the main method?
I want to be able to call the Competitor.getSurname and Competitor.getGivenname of CompetitorList[i]

Any help will be greatly appreciated! i've been stuck for a while!



  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    _ || || free ebooks and video tutorials about \ Java, C#, R, Assembly, C++, Perl, Visual Basic, JavaScript, Ruby, Delphi, PL/SQL, PHP, Visual Basic .NET, Swift, Python, C, Objective-C, Go, Scratch, MATLAB Crystal, Lisp, Prolog, Rust, Lua, Erlang, F#, Awk, Clojure, LabVIEW, FoxPro, Ada, Logo, Hack, Fortran, ABAP, Julia, Dart, Bash, SAS, Scheme, Alice, Apex, Scala, Transact-SQL, Kotlin, COBOL, VBScript, ML, D \ ___________

Sign In or Register to comment.