File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can i access myArray from my other classes?NEWBIE here

 
forno
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i created a class called LoadArray. In it I declare a public int array:
public int myArray;
I then load this array with data I read in from a parm file. a very BIG file.
-------------
How can I access myArray from my other classes?
I do not want to call LoadArray over and over...
This would cause myArray to be loaded over and over....
I am new to java as u can see.....help would be appreciated.
Thanks
 
Rob Ross
Bartender
Posts: 2205
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your code. Try to just include the bare minimum to describe the problem clearly.

Rob
 
Dave Vick
Ranch Hand
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
forno
Welcome to the Java Ranch, we hope you’ll enjoy visiting as a regular however, your name is not in keeping with our naming policy here at the ranch. Please re-register under an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
forno,
If you declare a static variable to hold your array, then there will only be ONE for the entire class instead of one for each instance of the class.
Is that what you mean?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yeah, you would get at the array by using the classname
If for example in class LoadArray:
static String[] myArray = new String[10000];
Then you can use:
LoadArray.myArray[whateverIndex];
to get at a particular element of the array, or just to get at the whole thing:
LoadArray.myArray
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic