• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Convert String [] to ArrayList<Long> ()

 
Greenhorn
Posts: 24
Android MyEclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 MyEclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to avoid looping, so any solutions without using loops ?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 MyEclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks you all for your helpful suggestions! I decided to go with using loops.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . and welcome to JavaRanch
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic