aspose file tools*
The moose likes Beginning Java and the fly likes Please Help - Using an Array from another class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please Help - Using an Array from another class" Watch "Please Help - Using an Array from another class" New topic
Author

Please Help - Using an Array from another class

Gus Parker
Greenhorn

Joined: May 10, 2009
Posts: 19
Hello, I'm new to JAVA and I'm trying to pass an array from one class to another, but I can't get it right. I've been able to get individual values on at a time.

If any one can help me out and give me a quick sample of how to do it,
I've done this below.

Is it as simple as an individual value - but just calling it an array - instead of say a string - or is it more complex. Please Help





Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Is it as simple as an individual value - but just calling it an array - instead of say a string - or is it more complex. Please Help


A string is an object. An array is an object. Passing either around is just passing an object around. What problem have you run into that you see it as different?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Bhagat Singh Rawat
Ranch Hand

Joined: Apr 04, 2009
Posts: 93
I couldn't understand what are you doing in your code. But if you want to run the existing code then make the following changes in BoxVol Class:



Brainbench Java 2.0 Fundamentals, J2EE 1.4
http://www.brainbench.com/transcript.jsp?pid=8192792
Gus Parker
Greenhorn

Joined: May 10, 2009
Posts: 19
Bhagat Singh Rawat wrote:See the changes in BoxVol Class:



aaaah I see, dont have a compiler right now to test, but that makes perfect sense, such a small thing, thank you very much for your reply, much appreciated.
Gus Parker
Greenhorn

Joined: May 10, 2009
Posts: 19
Henry Wong wrote:
Is it as simple as an individual value - but just calling it an array - instead of say a string - or is it more complex. Please Help


A string is an object. An array is an object. Passing either around is just passing an object around. What problem have you run into that you see it as different?

Henry


Thanks Henry for clearing that up, I'm still new and that helps me out, Much Appreciated.
Gus Parker
Greenhorn

Joined: May 10, 2009
Posts: 19
Oh yeah and one last thing,
so if i want to print can I use:

System.out.println("Volume is : " + vol.length);

can i also use

System.out.println("Volume is : " + vol[2]);

is that correct?

Just as normal?
jittu goud
Ranch Hand

Joined: Mar 30, 2007
Posts: 46
Gus Parker wrote:Oh yeah and one last thing,
so if i want to print can I use:

System.out.println("Volume is : " + vol.length);

can i also use

System.out.println("Volume is : " + vol[2]);

is that correct?

Just as normal?


if you want to print the volume array ....use the for loop to print ...
similar to you used in Box class
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Just one note: BoxVol can now change the elements of the array. This will also change the array in Box, since it is the same array.

If you don't want that, you can return a copy of the array:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please Help - Using an Array from another class