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

Returning all elements of an array

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys, I have tried searching the Java API and I am not finding a clear answer.

I have a class where I compute the word length frequency from a text file. And in it I create an array that stores the values. In my return statement how can I return all of the values in a nice table format?

Thanks.
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm afraid "nice table format" is ambiguous. Do you want a Swing table in a GUI? Perhaps SWT? Or is it text output, you want to format things with fixed-width fonts or tab characters? Are you trying to output to a spreadsheet?

When posting questions, keep in mind that we have no context -- don't know what you're trying to do or what equipment you have or who will use the final outcome or how. You have to provide the context for us.

rc
 
Ranch Hand
Posts: 97
MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jack Sloan wrote: In my return statement how can I return all of the values in a nice table format?

Thanks.



I think you want to display the values in a formatted way rather than return the array to some other method for further processing. In that case, you may use use GUI, swing and all, or if it is a text file, you may probably use the String formatting features of java.

Regards,
Gaurav Sagar
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As said by Gaurav and Ralph, using JTable would be an easier option but if its too much for the implementation and you would want to print them on the console- You can convert the array into a large String with the require formatting- look at String#format() and then return the String/print the String on to the console. Or another way would be to create a custom class with a field for storing this array and override its toString method to return the formatted String.
 
Don't touch me. And dont' touch this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic