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?
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.
Jack Sloan wrote: In my return statement how can I return all of the values in a nice table format?
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.
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.