Let's say I have this class:
public class MyClass {
private String propertyOne;
private String propertyTwo;
// getters setters...
}
Now, in my test method, I am trying something like:
List<MyClass> myList = myListDao.findAll();
String aStringFullOfPropertyOnesOfAllMyObjects = Joiner.on(", ").join(myList.iterator());
The String
, I want to get back is something like:
"propOneOfObjectOne, propOneOfObjectTwo, propOneOfObjectThree"
How can I do this?
The "old-school" solution:
You could use the built-in standard StringBuilder:
Using Joiner:
Using
Joiner
from the linked answer: