GeeCON Prague 2014*
The moose likes Java in General and the fly likes Totally stuck on how to approach a code porting from JavaScript to Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Totally stuck on how to approach a code porting from JavaScript to Java" Watch "Totally stuck on how to approach a code porting from JavaScript to Java" New topic
Author

Totally stuck on how to approach a code porting from JavaScript to Java

Carlos Romero
Greenhorn

Joined: Feb 06, 2013
Posts: 3
Hello everyone!

I was assigned to port a piece of code, but I'm stuck.

Let's see, the original code seems to generate a matrix of empty arrays, then populate it with booleans





So far I've extracted that nested function and ported the easy stuff, but I'm stuck on the for loops. I don't know whether to make the matrix using primitive arrays or use Collections (ArrayList for example). I know that it's always better to use Collections and using primitive arrays is generally wrong... but then I don't know how to do it. Oh, and this is for a little Android App.


A hint or some help will be greatly appreciated. Thanks!
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2853
    
  11

Hi Carlos, welcome to JavaRanch!

I don't know I'd say Collections are always better than arrays. ArrayLists are more flexible, but arrays take less space and might be easier to work with. In any case, as near as I can tell from what the JavaScript is doing, you'd instantiate an array like:



If you want to use Lists, it would be something like:



I'd stick with arrays of booleans until you have a compelling reason not to.
Carlos Romero
Greenhorn

Joined: Feb 06, 2013
Posts: 3
I've been busy lately, sorry for not replying. Thanks for the answer, it will help. ^^
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Totally stuck on how to approach a code porting from JavaScript to Java