jkteater
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;
}
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;
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
and assign in the constructor:
public class MyClass{
ArrayList a;
MyClass(ArrayList a){
this.a = a;
}
...
Then it will be accessible everuywhere