Solved

output the values in an array

Posted on 2014-01-10
9
437 Views
Last Modified: 2014-01-30
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
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 12

Assisted Solution

by:Sharon Seth
Sharon Seth earned 100 total points
ID: 39773387
It mans it is a great way to use ToStringBuilder.reflectionToString() in toString() to print your array of complex types .
0
 
LVL 37

Accepted Solution

by:
zzynx earned 400 total points
ID: 39775896
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
 
LVL 7

Author Comment

by:gudii9
ID: 39783961
in this link where they used

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

Any other links to understand this concept better
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:zzynx
ID: 39784663
>> where they used
In the class TestClass.
Method:

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

Open in new window

0
 
LVL 7

Author Comment

by:gudii9
ID: 39797891
the ArrayTest class contains an inner class called TestClass.

I wonder why author used inner class in this case. please advise
0
 
LVL 37

Expert Comment

by:zzynx
ID: 39803213
In this (simple) case TestClass could have been perfectly a "global" class too.

When should inner classes be used in Java?
0
 
LVL 7

Author Comment

by:gudii9
ID: 39816223
I wonder what  is a need for inner class even after reading the link you posted.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 39817054
That article gives a nice example. I can't do any better. Sorry.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 39820466
Thanx 4 axxepting
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question