• Post Reply Bookmark Topic Watch Topic
  • New Topic

get all the value from this array?  RSS feed

 
Cougar Vis
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My array

what is the sytax to get all the value out from those varible in this array? i.e. cIDIn, cFirstNameIn, cLastNameIn, cGenderIn,cAddressIn ,coNameIn, coAddressIn.

THANX

[ edited to break long lines and remove odd formatting -ds ]
[ May 17, 2004: Message edited by: Dirk Schreckmann ]
 
Rikko Verrijzer
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I should implement the toString method in the Customer class, which simply appends all values into one string. (like "cIDIn "+ cIDIn +" cFirstNameIn "+cFirstNameIn etc...), and then itterate through the array, and call toString on each object in the array. Assuming you want to do this for some screendump or something like that.

Hope this helps?
Rikko
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are looking to print a visual representation for those values, the common method is to write a toString() method in your Customer class then iterate over the array calling system.out.println with the current array element.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GK Leo,

As you're working to understand arrays in Java, you might find the following free lessons useful.
  • Sun's Java Tutorial on Arrays
  • Chapters 46-49 of Bradley Kjell's Introduction to Computer Science using Java
  • Chapter 8 of David J. Eck's Introduction to Programming Using Java
  • Dick Baldwin's Java Programming Tutorials (search for the word "array" on the page)


  • [ May 17, 2004: Message edited by: Dirk Schreckmann ]
     
    Dirk Schreckmann
    Sheriff
    Posts: 7023
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    what is the sytax to get all the value out from those varible in this array?

    That depends on how the Customer class is defined.

    Note that the code

    cArray [0] = new Customer (...

    added a Customer object to the array, not the variables cIDIn, cFirstNameIn, cLastNameIn, etc.

    You can access that Customer object with the syntax cArray[0]. This gives you a reference to the Customer object, which was constructed using the values of the variables cIDIn, cFirstNameIn, cLastNameIn, etc.

    So, you can perhaps access those values through the Customer object reference.

    Are you getting the idea?
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!