Newsletter |
How To Convert ArrayList to String Array In Java
Core Java » on Sep 27, 2012 { 25 Comments } By Sivateja
Hi friends, In java some times we may need some conversions from collection objects to some thing, ArrayList to String array is very popular conversion we are using in our projects 🙂
import java.util.ArrayList; import java.util.List; public class Java4s { public static void main(String args[]){ List al = new ArrayList<String>(); al.add("One"); al.add("Two"); al.add("Three"); al.add("Four"); al.add("Five"); String[] stringArrayObject = new String[al.size()]; al.toArray(stringArrayObject); for(String temp : stringArrayObject) System.out.println(temp); } }
Explanation
Line number 8 created ArrayList object
Line numbers 10,11,12,13,14 added data into list object
Line number 16 created String array, and at 17 we converted List data into String array
Finally output 😉
You Might Also Like
::. About the Author .:: | ||
Comments
25 Responses to “How To Convert ArrayList to String Array In Java”
why comparable and comparator two interfaces are there is java one is enough to sort and why comparable is in java.lang and why comparator is in java.util ?
Your technical information related with java programming is very useful and interesting. Also share updated details about java in your website. Thanks for sharing this article.
Awesome I want more collections tricky questions
This information you provided in the blog that was really unique I love it!!, Thanks for sharing such a great blog..Keep posting..
Are you create a scenario that is use only comparable interface not use campartor and revese
Really your blog is unique and understandable for new learner…..Thanx
good answer brother
Nice articles, great job
Find More information on Core Java Tutorials and Big Data
http://www.techburps.com
i am very happy to learn in this site.
The concepts given are clear to understand and more helpful for beginners like me Thank you.
Good tutorials with clear concept explaination helps for every one
gud explanation……siva teja…..
why comparable and comparator….
assume you have one list of objects like student..
requirement is something I want sorting by name,roll number and class.
if you use comparable interface,you can sort by only one value
when you use comparatore,you can done every sorting in one list
Hi sivateja Good Explanation.I Want more logical Answers from corejava. Thaks.
Nice Post
Sir please provide about concurrent collection also. and some important interviews question from hibernate and spring
Useful post. It is really helpful.
Thanks for sharing this webpage.
this is really too useful and have more ideas from yours. keep sharing many techniques. eagerly waiting for your new blog and useful information. keep doing more.
Nice blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it.
COMPARABLE AND COMPARATOR:
Comparable is default natural sorting order i.e ascending order. you just implement comparable interface and override compare method. no need to write logic inside that method.
Comparable: it is also inteface. if we want ascending and decending order then we need to use comparator interface
Can u people please provide example programs for every topics in core java, that will be great help full to us.
Nice blog has been shared by you. it will be really helpful to many peoples who are all working under the technology.thank you for sharing this blog.
Great conversation is going about java. This post will be very supportive for every Java developer.
Very helpful informative post. Thank you so much for sharing this Blog!!!