GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Creating instance of a non-static array method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating instance of a non-static array method" Watch "Creating instance of a non-static array method" New topic
Author

Creating instance of a non-static array method

Peter Taylor
Greenhorn

Joined: Mar 23, 2013
Posts: 2
Hello Everyone!

My problem is basically the following. I would like to get out data from a non-static array, so in order to do that I must make an instance of it. My problem is that I don't really now how to do that.

My code looks like the following, and it is obviously wrong:


I could solve this problem if I made Values static, but I cannot do that because Values array comes from a package, the source code of which I don't own.. So basically my question is about getting the value of a non-static array method. I know it's a very easy problem, but I would be really thankful if someone could guide me towards the solution to this basic problem. Thanks in advance!
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6



Also note that, by convention, Values() should be values()--methods and variables start with a lowercase letter.

And finally, not that it's a big deal here, but still something to be aware of, every time you call Values() (that is, both iterations of your for loop), you're creating a new array. And the way you're doing it, you're only using one value from each array and ignoring the rest. The usual way to do it would be to call the method once, store the results in a variable, and then use that variable for the iteration.
Peter Taylor
Greenhorn

Joined: Mar 23, 2013
Posts: 2
Thank you very much, I finally resolved this problem in the way you mentioned in the second half of your post. I've never found a site before, where people are this helpful with beginners, thanks again!
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

You're welcome! I'm glad it's clear now.
 
GeeCON Prague 2014
 
subject: Creating instance of a non-static array method