Solved

Using my ArrayList from any method

Posted on 2011-09-19
4
316 Views
Last Modified: 2012-05-12
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;
}
0
Comment
Question by:jkteater
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36562661
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
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36562672

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
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 50 total points
ID: 36562673
Create your ArrayList as a class variable something like this:

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

    private ArrayList<RevDataset> aList;

    public SelectedTModel() {
        super();
        this.aList = EdiSelection.rds;
    }
}

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36562681

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
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maven disable workspace resolution 1 38
Why doesn't this text field show up on my Applet frame? 2 28
Setup GlassFish 4 35
dao vs facade design patterns 2 32
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question