Convert string in list objects to comma seperated
I have a arraylist of objects, where one of the instance variable in the
object is string. I would like to convert the string variables in the
object list in to a single comma separated string.
For example,
I have an object employee as below.
public class Employee {
private String name;
private int age;
}
Consider a list of employees,
List<Employee> empList = new ArrayList<Employee>
Employee emp1 = new Employee ("Emp 1",25);
Employee emp2 = new Employee ("Emp 2",25);
empList.add(emp1);
empList.add(emp2);
Expected output (Type : String):
Emp 1,Emp 2
I know it can be done throug looping. But i looking for some sophistacated
way to do it and keep the code simpler.
Pls help.
No comments:
Post a Comment