Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Carlos Romero
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been busy lately, sorry for not replying. Thanks for the answer, it will help. ^^
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic