Note that there are some explanatory texts on larger screens.

plurals
  1. POArray List looping for a duplicate value
    primarykey
    data
    text
    <p>I am looking if there is an "easy" or simple way to make an array of something, Lets say Icecreams.. this would be a class of icecream with various Attributes (ID, flavour, Size, scoops), i would like to run an array that gathers every ice cream ordered and then searches through this list for any duplicate values (2+ same size)</p> <p>First idea i had was a for loop that creates the array than grabs the ice cream ID for the first instance, and checks its "flavour" against the array, if no duplicate is found the ID is increased by 1 (ID++) and then that Ice creams flavour is ran in the array, if a match is found i would set a Boolean to true.</p> <p>Every approach i seem to take appears to be rather long winded and i haven't got one working as of yet. hoping some fresh/more experienced eyes would help on this.</p> <p>In answer to below; The XML would hold something like below</p> <pre><code>&lt;iceCream id=1&gt; &lt;flavour&gt;chocolate&lt;/flavour&gt; &lt;scoops&gt;5&lt;/scoops&gt; &lt;/iceCream&gt; &lt;iceCream id=2&gt; &lt;flavour&gt;banana&lt;/flavour&gt; &lt;scoops&gt;2&lt;/scoops&gt; &lt;/iceCream&gt; </code></pre> <p>I would want to use drools (probably an array list?) to gather each icecream tag and allow me to check if any of the icecreams have the same flavour and output something (set a boolean to true) if a match is found, My understand was to make an array then run each icecream though the array by using its ID to identify it and inside each loop do ID +1 (int ID = 1) then in the lopp ID++. Aswell as search through the flavour childtag.</p> <pre><code>int ID = 0; boolean match = false; ArrayList iceCreams = new ArrayList($cont.getIceCreams()); for(iceCream $Flavour: (ArrayList&lt;iceCream&gt;)iceCreams) { ID++ if($Flavour.getFlavour().equals(icecream with id of (ID variable).getFlavour) { match = true; } } if(match) {etc etc etc} </code></pre> <p>Something along these lines if this helps?</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