How do I perform this MutliArray setup in Java?
Posted
by Andy Barlow
on Stack Overflow
See other posts from Stack Overflow
or by Andy Barlow
Published on 2010-03-24T14:55:59Z
Indexed on
2010/03/24
20:13 UTC
Read the original article
Hit count: 272
I come from a PHP background and I'm just getting my teeth into some Java. I was wondering how I could implement the following in Java as simply as possible, just echoing the results to a terminal via the usual "System.out.print()
" method.
<?php
$Results[0]['title'] = "No Country for Old Men";
$Results[0]['run_time'] = "122 mins";
$Results[0]['cert'] = "15";
$Results[1]['title'] = "Old School";
$Results[1]['run_time'] = "88 mins";
$Results[1]['cert'] = "18";
// Will basically show the above in order.
foreach($Results as value) {
echo $Results[$value]['title'];
echo $Results[$value]['run_time'];
echo $Results[$value]['cert'];
}
// Lets add some more as I need to do this in Java too
$Results[2]['title'] = "Saving Private Ryan";
$Results[2]['run_time'] = "153 mins";
$Results[2]['cert'] = "15";
// Lets remove the first one as an example of another need
$Results[0] = null;
?>
I hear there are "list iterators" or something that are really good for rolling through data like this. Perhaps it could be implemented with that?
A fully working .java
file would be most handy in this instance, including how to add and remove items from the array like the above.
P.S. I do plan on using this for an Android App in the distant future, so, hopefully it should all work on Android fine too, although, I imagine this sort of thing works on anything Java related :).
© Stack Overflow or respective owner