• Post Reply Bookmark Topic Watch Topic
  • New Topic

Returning all elements of an array  RSS feed

 
Jack Sloan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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.
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • 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
 
Gaurav Sagar
Ranch Hand
Posts: 97
Java MySQL Database
  • Mark post as helpful
  • send pies
  • 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
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!