Note that there are some explanatory texts on larger screens.

plurals
  1. PODoesn't return the ArrayList of arrays in java
    text
    copied!<p>getVariations method is used to obtain integer arrays which consist of same number of values in each but in different indexes. All these combinations are added to an arraylist called "combination" and it returns an arraylist of arrays. But when it's used as this in the main method</p> <pre><code> int[] cp1 = { 1,5,4,3,2}; ArrayList&lt;int[]&gt; k1 = sol.getVariations(cp1); for(int n=0; n&lt;5 ; n++){ int[] ab = k1.get(3); System.out.print(ab[n]); } </code></pre> <p>k1 doesn't contain the desired results. Yet couldn't find out what I'm doing wrong here. When the arraylist "combination" is checked inside this method it gives the desired results. It contains the arrays which were changed and added. But using the method's return arraylist outside the method can't get the work done.<br> Appreciate a lot if somebody can help.</p> <pre><code> public ArrayList&lt;int[]&gt; getVariations(int[] copy){ int[] cp1 = copy; int[] comb = new int[5]; Boolean b = false; Boolean d = false; Boolean e = false; int m = 0; ArrayList&lt;int[]&gt; combination = new ArrayList&lt;int[]&gt;(); for(int i=0; i&lt;N ; i++){ aloop: for(int j=0; j&lt;N ; j++){ for(int k=0; k&lt;N ; k++){ if(k==i) { b = true; e = true; } if(k==i+1){ d = true; e = false; } if(k==j){ b = false; e = true; continue; } if(b &amp;&amp; j&gt;=i) comb[k] = cp1[k+1]; if(!b &amp;&amp; j&gt;=i) comb[k] = cp1[k]; if(e &amp;&amp; j&lt;i){ comb[k] = cp1[k-1]; } if((j&lt;i || d ) &amp;&amp; j&lt;i &amp;&amp; !e){ comb[k] = cp1[k]; } } comb[j] = cp1[i]; b = false; e = false; d = false; for(int h=0 ; h&lt;N ; h++){ if(comb[h] == cp1[h]){ b = true; } else{ b = false; break; } } if(b){ b = false; continue aloop; } combination.add(m , comb); m++; for(int n=0; n&lt;N ; n++){ int[] ab = combination.get(m-1) ; System.out.print(ab[n]); } System.out.println(""); } } System.out.println(""); return (combination); } </code></pre>
 

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