Solved

output the values in an array

Posted on 2014-01-10
9
416 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
  • 5
  • 3
9 Comments
 
LVL 12

Assisted Solution

by:Sharon Seth
Sharon Seth earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
in this link where they used

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

Any other links to understand this concept better
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
>> where they used
In the class TestClass.
Method:

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

Open in new window

0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 7

Author Comment

by:gudii9
Comment Utility
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
Comment Utility
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
Comment Utility
I wonder what  is a need for inner class even after reading the link you posted.
0
 
LVL 37

Expert Comment

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

Expert Comment

by:zzynx
Comment Utility
Thanx 4 axxepting
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now