• 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

Printing Multidimensional Arrays

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, i want to print my Array in text field like that:
element1 : element2
element1 : element2
I am using getter to get an ArrayList value and toString to print it, but i can't print it, i dont know where to put [i] and [j].

Code for print:



Code for getter:




I am using tutorial from there:   https://www.wikihow.com/Print-an-Array-in-Java
Check for method 3 to fully understand me.
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i want to print my Array in text field like that:  


A text field contains a single line.  Can you show how the array would be displayed?
Can you post a sample array and how you want to display its contents?
For example given a 2 dim array: {{,12}, {3,4,5}, {6}}
What would the display look like?
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:

i want to print my Array in text field like that:  


A text field contains a single line.  Can you show how the array would be displayed?
Can you post a sample array and how you want to display its contents?
For example given a 2 dim array: {{,12}, {3,4,5}, {6}}
What would the display look like?



12
3 : 4 : 5
6
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My arraylist contains 2 elements
Name:  Mark:

I want to print them like that:
Element1:    Element2:
NameOfSomething:   Mark
NameOfSomething:   Mark
NameOfSomething:   Mark
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just lane by lane.
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, with a 2 dim array, each row goes on its own line with elements separated by ":"s

Use the concatenation with +  to build a line or elements and ":"s.
End the line with a "\n" character to move to the next line

Use the variables: row and column to index into the 2 dim array so you can easily see what element is being indexed. i and j don't describe what is happening.
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, can you give me simple example?
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know what to do but i can't attach argument row and column to getter.
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arek Wróbel wrote:Hey, i want to print my Array in text field like that:
element1 : element2
element1 : element2
I am using getter to get an ArrayList value and toString to print it, but i can't print it, i dont know where to put [i] and [j].

Code for print:



Code for getter:




I am using tutorial from there:   https://www.wikihow.com/Print-an-Array-in-Java
Check for method 3 to fully understand me.




runner.getGamesList()[i] [j].toString(); doesn't seems to work. How to type it?
 
Saloon Keeper
Posts: 10805
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you have a runner and that runner has a List<Game> and that Game has multiple fields that you'd like to present as columns in a printout. Could you please show us more code that shows what type 'runner' is and what its class ('Runner'?) looks like? And what your 'Game' class looks like? We're lacking enough info to help you properly.
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Sounds like you have a runner and that runner has a List<Game> and that Game has multiple fields that you'd like to present as columns in a printout. Could you please show us more code that shows what type 'runner' is and what its class ('Runner'?) looks like? And what your 'Game' class looks like? We're lacking enough info to help you properly.



Game class:




Runner class:

 
Carey Brown
Saloon Keeper
Posts: 10805
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you want a print out of a List<ObjectOfArray> (ie 'Game') so that you get:
Is this correct?
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:It looks like you want a print out of a List<ObjectOfArray> (ie 'Game') so that you get:
Is this correct?


Yes my friend : )
 
Carey Brown
Saloon Keeper
Posts: 10805
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That should do the trick. You already have the ability to get '<title>: <mark>' from the toString() method.

You've really got to come up with more meaningful names for your classes. 'ObjectOfArray' means nothing whereas 'Game' does.
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:That should do the trick. You already have the ability to get '<title>: <mark>' from the toString() method.

You've really got to come up with more meaningful names for your classes. 'ObjectOfArray' means nothing whereas 'Game' does.


Yeah, sorry, i know that's bad but  i just make those class for learning purposes and didn't care for naming. I know that is a bad habit . Thank you for you help.
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Carey Brown. Works like i wanted to.
 
reply
    Bookmark Topic Watch Topic
  • New Topic