my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Computing Items in anArray List from another method in the same class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Computing Items in anArray List from another method in the same class" Watch "Computing Items in anArray List from another method in the same class" New topic
Author

Computing Items in anArray List from another method in the same class

Imad Ali
Greenhorn

Joined: Jan 04, 2009
Posts: 21
I think my title explained abit of what I want done!


So Ive got files put into an array



And then I got files put into another array



Then how do I listFiles() the files in both arrays as if they were comming from one folder?
Becasue I want to compute all files from the arrays, to see which ones are the same size in bytes.




I dont know how the mehtod can view the arrays from its scope



Imad Ali
Greenhorn

Joined: Jan 04, 2009
Posts: 21
and the arrays dont have specifed lengths, they couuld have any amount fo files in them
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Why is this a problem? If an array is declared a class variable, as opposed to a method variable, then it should not be a problem to access that array from within a method in the same class. The only thing I can think might be a problem is if the method is static but the class variable (array) is not.

If you have declared the arraylist as a method variable, ask yourself if there is a reason why it can't be declared a class variable. That's one way to deal with it.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
Please don't say "class variable" unless you mean "static field". You probably would do better to use the proper jargon: "instance field." That would remove any confusion about whether it is static or not.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Campbell Ritchie wrote:Please don't say "class variable" unless you mean "static field". You probably would do better to use the proper jargon: "instance field." That would remove any confusion about whether it is static or not.


Duly noted. I should use the right words, that is indeed important. Anyways, my point was not so much the type of variable, but where it is defined, in the class as opposed to in the method, but you are right.

Anyways, not to quibble, but Sun uses the terminology class variables and static fields as meaning the same thing, associated with the class. And they tend to use the term instance variable for the other kind. I assume that's ok here.

http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html

regards.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
Instance field? Instance variable? Agree: what's the difference. And as I said "class variable" = static field. I don't think we disagree, just I am feeling pedantic today.

Actually there is a reason for being precise with jargon: it helps other professionals understand you with economy of words. Two words "static" and "field" and everybody knows what you mean.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Computing Items in anArray List from another method in the same class
 
Similar Threads
An object to hold several arrays
About multi-dimensional array
Arrays
Array types clarification ....
Stuffing one array into another