Solved

Arraylist into comma seprated list

Posted on 2009-04-09
6
2,110 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

758 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

21 Experts available now in Live!

Get 1:1 Help Now