• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and the arrays dont have specifed lengths, they couuld have any amount fo files in them
 
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
What's a year in metric? Do you know this metric stuff tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic