This post explains a Comma
Separated String to ArrayList using Java. I am using Java Generics for
Converting a Comma Separated String into
based on your DataType ArrayList.
Sample Java Program For
Converting String into List.
import
java.lang.reflect.Constructor;
import
java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
/**
* @author Venkata Ramu Kandulapati
*
*/
public class ConvertToList {
@SuppressWarnings("unchecked")
public <T>
List<T> toList(String comaSepString, T t) throws Exception {
List<T>
list = new
ArrayList<T>();
Constructor<?>
constructor = t.getClass().getConstructor(String.class);
for (String _s : comaSepString.split(",")) {
list.add((T) constructor.newInstance(_s));
}
return list;
}
public static void main(String args[]) throws Exception {
String
numberString ="1,2,3,4";
System.out.println(new
ConvertToList().toList(numberString, new Integer(0)));
String
comaSepString = "Windows,Ubuntu,IOS";
System.out.println(new
ConvertToList().toList(comaSepString, new String()));
}
}
Output of Above Program:
[1, 2, 3, 4]
[Windows, Ubuntu, IOS]
Explanation
In the above java Program convert the coma separated String into ArrayList.Your Coma separated String values may be String,Integer,Float or Double whatever the DataType this program is convert into ArrayList based on your Sending DataType.
Thanks for sharing your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
ReplyDeleteRegards,
JAVA Course in Chennai|Best JAVA Training in Chennai|JAVA Training
I really love reading and following your post as I find them extremely informative and interesting. This post is equally informative as well as interesting . Java Training Institute in Chennai | DotNet Training Institute in Chennai | Web Designing Training Institute in Chennai
ReplyDeletePretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
ReplyDeleteDigital Marketing Training in Chennai | SEO Training Institute in Chennai | Photoshop Training in Chennai
Hi, am a big follower of your blog. I am really happy to found such a helpful and fascinating post that is written in well manner. Thanks for sharing such an informative post. keep update your blog.
ReplyDeleteNo.1 Software Testing Training Institute in Chennai | Best Selenium Training Institute in Chennai | ISTQB Certification Center in Velachery
I’m really impressed with your blog article, such great & useful knowledge you mentioned here.MBA Project Center in Chennai | MBA Project in Velachery.
ReplyDeleteHi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.
ReplyDeleteI enjoy what you guys are usually up too. This sort of clever work and coverage! Keep up the wonderful works guys I’ve added you guys to my blog roll..,
ReplyDeletewhite label website builder
mobile website builder
I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
ReplyDeleteaws training in Chennai
Those guidelines additionally worked to become a good way to
ReplyDeleterecognize that other people online have the identical fervor like mine
to grasp great deal more around this condition.
white label website builder
Excellent Article !
ReplyDeleteThank you very much for your hard work...
Summer Courses for Business Administration in Chennai | Best Summer Courses in Porur
Wonderful post..Thank you for sharing...Summer Courses in Chrompet | Summer Courses in Chennai
ReplyDeleteInteresting post. This is really helpful for me. I like it. Thanks for sharing.
ReplyDeleteBest IT Training Institute in Chennai |Best IT Training Institute in Velachery
I read this article. I think You put a lot of effort to create this article. I appreciate your work.
ReplyDeleteDissertation Writing Services
ReplyDeleteHello, I read your blog occasionally, and I own a similar one, and I was just wondering if you get a lot of spam remarks? If so how do you stop it, any plugin or anything you can advise? I get so much lately it’s driving me insane, so any assistance is very much appreciated.
AWS Training in Chennai | Best AWS Training in Chennai
Best Data Science Training in Chennai
Best Python Training in Chennai
Best RPA Training in Chennai
Digital Marketing Training in Chennai
Matlab Training in Chennai
Best AWS Course Training in Chennai
Best Devops Course Training in Chennai
Java Training Institute in Chennai
C C++ Training in Chennai
Very super article! I really happy to read your post and I got different ideas from your great blog. I am waiting for more kinds of posts...
ReplyDeleteTableau Training in Chennai
Tableau Course in Chennai
Excel Training in Chennai
Oracle Training in Chennai
Oracle DBA Training in Chennai
Power BI Training in Chennai
Embedded System Course Chennai
Linux Training in Chennai
Tableau Training in Chennai
Tableau Course in Chennai
This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
ReplyDeleteBig Data Analytics Courses in Chennai
Big Data Analytics Training in Chennai
Python Training in Chennai
Java Training in Chennai
Software Testing Training in Chennai
Big Data Analytics Training in Porur
Big Data Analytics Training in Adyar
Thanks for this greatful information. all this information is very important to all the users and can be used good at all this process
ReplyDeleteBest Tally ERP 9.0 Training Academy in Kanchipuram
Your article was so impressive and informative. Its very interesting to read. Thanks for sharing,
ReplyDeleteBest web design Training Institute in Kanchipuram
Nice article. I liked very much. All the informations given by you are really helpful for my research. keep on posting your views.
ReplyDeleteccna course in bangalore
ccna course in Chennai
ccna Training in Chennai
ccna training in bangalore
ccna course in Coimbatore
ccna course in Madurai
ccna training in madurai
ccna training in coimbatore
Excellent post. I have read your blog it's very interesting and informative. Keep sharing.
ReplyDeleteBest JAVA / J2EE / J2ME Course Training Institute in kanchipuram|
Nice post.. Really you are done a wonderful job. Thanks for sharing such wonderful information with us. Please keep on updating...
ReplyDeleteBest C & C++ Course Training Institute in kanchipuram|