• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please Help - Using an Array from another class

 
Gus Parker
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21490
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bhagat Singh Rawat
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
Gus Parker
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic