wood burning stoves 2.0*
The moose likes Java in General and the fly likes Convert String [] to ArrayList<Long> () Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Convert String [] to ArrayList<Long> ()" Watch "Convert String [] to ArrayList<Long> ()" New topic
Author

Convert String [] to ArrayList<Long> ()

Arun Vasu
Greenhorn

Joined: Oct 05, 2010
Posts: 24

Hi,

Could anyone help me to convert an array of String to ArrayList of Long type.

Like String [] to ArrayList<Long>() using any java API?

Thanks,
Arun
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Try using a simple loop combined with any methods / constructors of java.lang.Long.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Arun Vasu
Greenhorn

Joined: Oct 05, 2010
Posts: 24

I need to avoid looping, so any solutions without using loops ?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18523
    
  40

Arun Vasu wrote:I need to avoid looping, so any solutions without using loops ?


What's wrong with loops?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
Arun Vasu wrote:I need to avoid looping, so any solutions without using loops ?


That's not really how this works. What did you try? Where are you stuck? What worked? What didn't work? How didn't it work? Be specific and post code that demonstrates what you've tried.
Show some effort.

Why do you need to avoid looping?
Do your own homework.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

No. Turning a String[] into an ArrayList<String> - not a problem. Turning an ArrayList<String> into a String[] - not a problem. But because you need to convert each String into a Long you have no other option than to use a loop.

Actually, all solutions include a loop. The loop may be hidden for you (e.g. the ArrayList(Collection) constructor, List.toArray(...)) but it's still there.
Arun Vasu
Greenhorn

Joined: Oct 05, 2010
Posts: 24

Thanks you all for your helpful suggestions! I decided to go with using loops.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37986
    
  22
. . . and welcome to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convert String [] to ArrayList<Long> ()
 
Similar Threads
String array to arraylist
convert a String to Long
return string array
Convert ListArray to string array
converting float hex to int