This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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
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!!
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
posted
0
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: How can i access myArray from my other classes?NEWBIE here