aspose file tools*
The moose likes Beginning Java and the fly likes transfering variable arrays between classes?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "transfering variable arrays between classes??" Watch "transfering variable arrays between classes??" New topic
Author

transfering variable arrays between classes??

hugh slater
Greenhorn

Joined: Apr 02, 2002
Posts: 2
new to java and writing a program that includes reading a file to set an array for a combo box
my first idea was to have a seperate class to read the file and transfer the resulting array to the main class - however this seems not to be possible - return returns objects, integers, strings and doubles, but not in arrays. Is there any 'approved' method of doing this or should the method to read in the file reside in the main class???
thanks in advance
aminur rashid
Ranch Hand

Joined: Sep 21, 2001
Posts: 79
Hi hugh
Instead of using arrays you can use any of these Vector / Hashtable/Enumeration/Collection
cheers


Regards<br />Aminur
Kris Philippaerts
Greenhorn

Joined: Oct 19, 2001
Posts: 25
Hi there.
First of all, using different classes and different objects is what's Java is all about. Putting this code in a different class will make it possible to re-use this code troughout your entire project. So you don't have to write the exact same code in 5 different places in your project.
Java has a lot of 'data-store' classes. Just go and look at the Collection interface in the Java docs. By clicking the known subinterfaces (List, Set, SortedSet), you will eventualy find all subclasses you can use as a collection. A little different, but oh so useful, is the HashMap. Go and read the docs, you'll see how to use it. And to use it, basically typ something like:
List getStringList() {
List lst = new Vector(); // because List is an interface
...
return lst;
}
void anOtherFunction() {
...
List lst = getStringList();
...
}
And finally, java can return arrays. For example:
String[] getStringArray() {
String[] str = new String[10];
...
return str;
}
void anOtherFunction() {
...
String myArray = getStringArray();
...
}
Hope this helps
Kris
Zakaria Haque
Ranch Hand

Joined: Jan 02, 2002
Posts: 60
java arrays are object as well. use ObjectInputStream.readObject() and cast the result as your desired array type. If you serialized an array of ComboBox, try this
ComboBox[] boxes = (ComboBox[]) in.readObject();

Hope it helps.


tobe bondhu nouka bherao<br />shonabo gaan aj shara raat
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
hugh
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 change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!


Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: transfering variable arrays between classes??