Results 1 to 4 of 4
  1. #1
    ankit1801 is offline Member
    Join Date
    Mar 2011
    Posts
    20
    Rep Power
    0

    Default Converting Arraylist to String array

    i have one arraylist named species containing strings. i need to put the data in to a String array called species_name. how do i do this?

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    There may be a method for it, check the list and arraylist API for a method that does it. If t doesn't exist you can easily do this by first creating an array of strings equal to the size of the arraylist, then loop through and add items to the array.

  3. #3
    ankit1801 is offline Member
    Join Date
    Mar 2011
    Posts
    20
    Rep Power
    0

    Default

    the toArray method requires an 'Object' . can i use this method with any modifications in it?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,784
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by ankit1801 View Post
    the toArray method requires an 'Object' . can i use this method with any modifications in it?
    I guess you just skimmed through the API documentation for the ArrayList class, because the answer is right there:

    Quote Originally Posted by API
    <T> T[] toArray(T[] a)
    Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.
    Always first read the API documentation before you start guessing and before you start asking questions here.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Converting an array program to ArrayList
    By Adomini in forum New To Java
    Replies: 4
    Last Post: 10-13-2010, 08:22 PM
  2. Converting ArrayList to Array
    By vasavi.singh in forum New To Java
    Replies: 1
    Last Post: 02-23-2009, 03:34 PM
  3. Converting a String into a array.
    By taraxgoesxboom in forum New To Java
    Replies: 12
    Last Post: 02-22-2009, 06:29 AM
  4. Converting ArrayList to Array
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-13-2007, 11:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •