Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert String [] to ArrayList<Long> ()  RSS feed

 
Arun Vasu
Greenhorn
Posts: 24
Android Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using a simple loop combined with any methods / constructors of java.lang.Long.
 
Arun Vasu
Greenhorn
Posts: 24
Android Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to avoid looping, so any solutions without using loops ?
 
Henry Wong
author
Sheriff
Posts: 22827
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun Vasu wrote:I need to avoid looping, so any solutions without using loops ?


What's wrong with loops?

Henry
 
Kevin Workman
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
Android Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you all for your helpful suggestions! I decided to go with using loops.
 
Campbell Ritchie
Sheriff
Posts: 53734
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to JavaRanch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!