Note that there are some explanatory texts on larger screens.

plurals
  1. POLoop through multiple list from one loop and assign the value into a String
    text
    copied!<p>My goal is to concat the value all together into one string from the value in different list. My string looks like this: '0 0 0'. The first 0 represents 'second', the second 0 represents 'minute', and the third 0 represents 'hour'. I've created three different list to contain the values. First one is a second list, second one is a minute list, third one is a hour list. After I create all three lists, I put those three lists into one master list. I'm trying to loop through the master list, then assign the value into those positions to create the string based on the size of those three list. Those three list size are identical.</p> <pre><code>import java.util.*; public class multipleList{ public static void main(String[] args){ ArrayList&lt;String&gt; seconds=new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; minutes=new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; hours=new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; masterList=new ArrayList&lt;String&gt;(); seconds.add("10"); seconds.add("20"); seconds.add("30"); minutes.add("15"); minutes.add("16"); minutes.add("17"); hours.add("2"); hours.add("3"); hours.add("4"); masterList.addAll(seconds); masterList.addAll(minutes); masterList.addAll(hours); for(String subList:masterList){ System.out.println(subList); } </code></pre> <p>}</p> <p>The output from console print is 10, 20, 30, 15, 16, 17, 2, 3, 4. Now my problem is how can I assign those values into the string after loop through the master list such as the first string will be '10 15 2' (format is 'second minute hour'), the second string will be '20 15 3' and the third string will be '30 17 4'.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload