Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 466
  • Last Modified:

output the values in an array

Hi,

I am going through below example
http://www.avajava.com/tutorials/lessons/whats-a-quick-way-to-output-the-values-in-an-array.html?page=2

ArrayUtils.toString() is a great way to display the values of simple data types. For more complex data types, like JavaBeansW, you can use ArrayUtils.toString() in conjunction with ToStringBuilder.reflectionToString() in the toString() method of your complex data type to display the values of your objects in your array.


I have not understood what author meant by above line.

please advise
Any links resources ideas highly appreciated. Thanks in advance
0
gudii9
Asked:
gudii9
  • 5
  • 3
2 Solutions
 
Sharon SethCommented:
It mans it is a great way to use ToStringBuilder.reflectionToString() in toString() to print your array of complex types .
0
 
zzynxSoftware engineerCommented:
For arrays of simple data types you can use ArrayUtils.toString() and that gives you the expected result "by default".

For complex data types (classes), you have to override the toString() method of those classes.
i.e. exactly specify how you want the string representation of an instance of your complex class to look like.

The sentence you don't understand states, that in the latter case, you can use ToStringBuilder.reflectionToString() in that toString() method code you write.
0
 
gudii9Author Commented:
in this link where they used

ToStringBuilder.reflectionToString() in that toString() method code you write.

Any other links to understand this concept better
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
zzynxSoftware engineerCommented:
>> where they used
In the class TestClass.
Method:

public String toString() {
    return "\n" + ToStringBuilder.reflectionToString(this);
}

Open in new window

0
 
gudii9Author Commented:
the ArrayTest class contains an inner class called TestClass.

I wonder why author used inner class in this case. please advise
0
 
zzynxSoftware engineerCommented:
In this (simple) case TestClass could have been perfectly a "global" class too.

When should inner classes be used in Java?
0
 
gudii9Author Commented:
I wonder what  is a need for inner class even after reading the link you posted.
0
 
zzynxSoftware engineerCommented:
That article gives a nice example. I can't do any better. Sorry.
0
 
zzynxSoftware engineerCommented:
Thanx 4 axxepting
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now