Solved

Arraylist into comma seprated list

Posted on 2009-04-09
6
2,132 Views
Last Modified: 2012-05-06
I have an arraylist of salesCycle object  and I want to convert this arraylist into a comma separated String. For example:
Arraylist of sales Cycle and salesCycle has one of the property cycleID  I need the following result :

String cycles =salesCycle.cycleId1, salesCycle.cycleId2,&
0
Comment
Question by:rajannagpal
[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
  • 4
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 24109820
You can do the following if your salesCycle object implements toString properly:
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24109827

String cycles = list.toString();

Open in new window

0
 

Author Comment

by:rajannagpal
ID: 24109875
what should under toString  method of salesCycle?
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 86

Expert Comment

by:CEHJ
ID: 24109946
The representation you want it to have, e.g.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24109953
publ
public String toString() {
    return "" + id;
}

Open in new window

0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 24112954
use the following:

public static String getSalesCycleString(List salesCyclesList) {
   StringBuilder sb = new StringBuilder();
   for (salesCycle cycle : salesCyclesList) {
      sb.append(cycle.getCycleId());
      sb.append(",");
   }
   return sb.length()==0 ? "" :  sb.substring(0, sb.length()-1);
}

0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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…
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…
This video teaches viewers about errors in exception handling.

726 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