Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Arraylist into comma seprated list

Posted on 2009-04-09
6
Medium Priority
?
2,169 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
  • 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
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 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 1000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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.
Suggested Courses

916 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