File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Large static arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Large static arrays" Watch "Large static arrays" New topic

Large static arrays

Tom Bigford

Joined: Nov 09, 2001
Posts: 8
Hi All ... I am retrofitting a java app/applet which contains a large static array
public static final byte[][] x = {{1,2,3},{4,5,6}... };
clearly this isn't a very safe array sine anyone can change the values...
Any ideas on the best way to handle a large pre-defined array like this?
TIA - Tom
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Make it private and provide getters and setters, and in those methods put in whatever controls that you feel you need.
Tom Bigford

Joined: Nov 09, 2001
Posts: 8
Thanks Cindy - I am looking for design ideas...There are several arrays of this data existing in the code - it is *ugly* - and also readily changeable. Your solution will work for the "readily changeable" part - but i would like to make this an elegant design ... At first i looked at an interface - but of course the data in an interface can only be public...(as well as static and final etc etc) - That leaves me in the same place ... This may be just too complicated to ask in this forum - but thanks for trying anyway...
Thanks again - Tom
Michael Ernest
High Plains Drifter

Joined: Oct 25, 2000
Posts: 7292

I dunno how 'elegant' one can get with a mass of arbitrary data -- most design patterns focus on de-coupling object relationships. Data typically just comes in a file.
And you could do it that way: feed the data into the program from a file, and make the file presentation itself cleaner. For example, you could treat each array as the values of some named property. If it's structured data you could even -- dare I say it -- store it in an XML-based format.
After that, it doesn't really get any better than encapsulation.

Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
I agree. Here's the link:
subject: Large static arrays
It's not a secret anymore!