Newsletter

How To Convert ArrayList to String Array In Java

Core Java » on Sep 27, 2012 { 24 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 .::

Java4s_Author
- Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

24 Responses to “How To Convert ArrayList to String Array In Java”
  1. prasad says:

    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 ?

  2. 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.

  3. jayendra says:

    Awesome I want more collections tricky questions

  4. This information you provided in the blog that was really unique I love it!!, Thanks for sharing such a great blog..Keep posting..

  5. Are you create a scenario that is use only comparable interface not use campartor and revese

  6. Divakar Singh says:

    Really your blog is unique and understandable for new learner…..Thanx

  7. reddy says:

    good answer brother

  8. eddie says:

    Nice articles, great job

    Find More information on Core Java Tutorials and Big Data
    http://www.techburps.com

  9. Sriramasai Amajala says:

    i am very happy to learn in this site.

  10. RamKumar says:

    The concepts given are clear to understand and more helpful for beginners like me Thank you.

  11. ramyasreelanke says:

    Good tutorials with clear concept explaination helps for every one

  12. sudheer says:

    gud explanation……siva teja…..

  13. Prakash Bariya says:

    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

  14. balakrishna says:

    Hi sivateja Good Explanation.I Want more logical Answers from corejava. Thaks.

  15. Arvind says:

    Sir please provide about concurrent collection also. and some important interviews question from hibernate and spring

  16. Useful post. It is really helpful.

  17. Thanks for sharing this webpage.

  18. anitha says:

    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.

  19. abar says:

    Nice blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it.

  20. saikrishna says:

    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

  21. sharath says:

    Can u people please provide example programs for every topics in core java, that will be great help full to us.

  22. zuan says:

    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.

  23. dharshini says:

    Great conversation is going about java. This post will be very supportive for every Java developer.

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2018 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.