• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

array

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
1.
i have
public static final int BOX = 0;
public static final int CIRCLE = 1;
if i want to put the elements into an array do the array have to be
public static final
or it can be private
and then i just write set and get methods to access and update array


2. is it how I use get and set methods?
private StringBuffer m[][];

// set methods
public void setm(int a[][])
{
m = a;
}
public int[][] getm()
{
return m;
}

any help appreciated
thanks
barbara
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey barbara,

You have your array initialized as StringBuffer, but you have data type as 'int' in setm() and getm(). I recommend that you change all 'int' into 'StringBuffer'. Plus, (m == a) will set the value of m, which is the memory location of the array, into the variable 'a'. You can have your arrays private. Private can be accessed within the class.



You might want to consider using loops to go through an array and access/modify it.

Here is an example:



In the example above, setM() will set the value "myValue" in the array, and the getM() will print "myValue" 10 times.
[ June 15, 2004: Message edited by: Dipen Javia ]
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
barbara, when you declare your ints as final, they are final, or in other words, they are accessible directly but immutable. So it doesnt matter whether your array is public or private. However, it depends on the use of your class whether you want to have the array private (need accessor methods) or public (dont need accessor methods).
One more thing, the way you pass your array, you only pass its reference to the method, so you want to create a new array inside the setm() and then copy the a[][] into that new array.

hope that helps.

ben
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic