Link to home
Start Free TrialLog in
Avatar of jkteater
jkteaterFlag for United States of America

asked on

Using my ArrayList from any method

I want to be able to access my ArrayList in any method in my class without having to pass it to the method.  Example would be

public int getRowCount() {
                  int rows = aList.size();
                   return rows;
               } // end getRowSize()

Where Alist is my ArrayList

I am putting ArrayList in the Constructor, but that don't seem to do it.

public SelectedTModel() {
      super();
     ArrayList<RevDataset> aList = EdiSelection.rds;
}
Avatar of for_yan
for_yan
Flag of United States of America image

you need to declare it as an intancwe varuiable
and assign in the constructor:
public class MyClass{
ArrayList  a;

MyClass(ArrayList a){

this.a = a;


}


...


Then it will be accessible everuywhere

when you do this in the constructior
  ArrayList<RevDataset> aList = EdiSelection.rds;
you aList becvomes a local; varaiable
of the constructorr

You need to assign arrauylit to sthe instance
varaible of your class, then it would be accesible anyware in the class
ASKER CERTIFIED SOLUTION
Avatar of wdosanjos
wdosanjos
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

when you do this in the constructior
  ArrayList<RevDataset> aList = EdiSelection.rds;

you declaration
 ArrayList<RevDataset> aList
hapopnes inside constructor - so it is local to the constructor

decalartion should be outside any method then it is an instance variable