• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

How do I access this array???

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
reply
    Bookmark Topic Watch Topic
  • New Topic