aspose file tools*
The moose likes Beginning Java and the fly likes How can i access myArray from my other classes?NEWBIE here Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How can i access myArray from my other classes?NEWBIE here" Watch "How can i access myArray from my other classes?NEWBIE here" New topic
Author

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

forno
Greenhorn

Joined: Jan 18, 2002
Posts: 1
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

Joined: Jan 07, 2002
Posts: 2205
Post your code. Try to just include the bare minimum to describe the problem clearly.

Rob


Rob
SCJP 1.4
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
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!!


Dave
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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?


"JavaRanch, where the deer and the Certified play" - David O'Meara
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can i access myArray from my other classes?NEWBIE here