• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I access this array???  RSS feed

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to access and manipulate the values of an array created in one object from a method in another object. What is the best way to do this? Can I pass the array into the current object? Would I do this by placing it as an argument in the constructor of the object? Or could I access the array by making the object that creates/holds it public?
For Example:
I have an object named arrayManipulator that works with values of an array.
I have 2-dimensional array of int values named myArray that was created in the arrayCreator object.
Would this be an appropriate Java statement to execute from within a method of the arrayManipulator object?
arrayCeator.myArray [2][4] = 6
Thanks for any suggestions.
Landon
 
author
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rather than breaking encapsulation by revealing or passing the array to an "array manipulator" object, why don't you just add another method to the class that is already holding the array, and do the manipulation in there?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!