Note that there are some explanatory texts on larger screens.

plurals
  1. POcopying elements of an array-list to the other array-list
    primarykey
    data
    text
    <p>I have written such a simple code:</p> <ul> <li><p>I have written this line in my class's constructor : <code>List element = new ArrayList();</code></p></li> <li><p>I have a variable named <code>cost</code> which its type is <code>int</code> </p></li> <li><p>one method will return three lists with different objects: <code>listOne, listTwo, listThree</code></p></li> <li><p>in another method I have written below code which this method will use those lists that are created in the method above.this method will be called three times for three lists above. each call for each list.</p> <pre><code>// begining of the method: int cost = 0; if(cost==0){ element = listOne; cost = 3; } if(cost&lt;4){ element = listtwo; cost = 6; } // end System.out.println(element.toString()); </code></pre></li> </ul> <p>Unfortunately, instead of printing <code>listTwo</code> it will print <code>listThree</code> (if we have 4 or more lists it will print the last one)!</p> <p>Is there any problem with if-else condition?</p> <p>thanks</p> <p>EDIT: this is my main code but its condition is like the code above: <code>auxiliaryList</code> in the code below is <code>listOne</code> or <code>list Two</code> or <code>listThree</code> respectively.</p> <pre><code>cost = 0; public void method { System.out.println(element.toString());//number one if (cost== 0) { element = auxiliaryList; cost = 3; } else if( cost&lt;4){ element =auxiliaryList; cost = 6; } } return; } } </code></pre> <p>also the line which is declared with <code>//number one</code> shows me that before going to the if/else condition ,the element list will be set to the current list in the method.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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