• 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

NX: URLy Bird 1.3.1 - ArrayList to Array Conversion

 
Ranch Hand
Posts: 493
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Does anyone know an efficient way of converting an ArrayList which stores Integer objects to an array of ints?
I think I have a pretty cool
int [] find(String [] criteria)
method implementation for the Data class. Except, I cannot covert the ArrayList which gathers the "good" records stored in the ArrayList to int [] array. Here is my code fragment which makes me kinda mad!

You can see my sledge-hammer conversion. I know, performance is not the criteria, but there is got to be a better way than this. retVal is the ArrayList in the above example.
Thanks.
Bharat
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bharat,
I don't think you are going to get much improvement, after all an ArrayList can contain any sort of object, so there is no implicit way of converting an ArrayList of Integers into an array of ints.
Combining the two lines in your 'for' statement's block should give a tiny performance increase (no need for the intermediate object). But this would potentially make the code a little harder to read. And unless this is where you have determined that a bottleneck occurs, then you shouldnt bother trying to save the few milliseconds that this might give you.
Regards, Andrew
 
Bharat Ruparel
Ranch Hand
Posts: 493
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Andrew,
Thanks for reviewing the code fragment for me. I spent two hours last night trying to make this work with retVal.toArray() conversion. But it returns an array of Objects! I was just trying to make the code a bit more elegant. Most of the other pieces of code are, especially locking stuff. But I see your point; "keep your eyes on the ball and don't get carried away too much."
Regards
Bharat
reply
    Bookmark Topic Watch Topic
  • New Topic