<p dir="ltr">Hello. In both examples you redeclare variable inside loop on each new iteration. This behaviour is shared for all c-like languages. Each time you enter a loop body, you "redeclare" (doubt it's JLS concept) variable and initialize it with value 1. In the end of loop you in fact increment variable, but it has no effect since variable is reinitialized on next loop iteration.<br>
Your best choice is to move variable intiialization right before the loop. This way you will get the desired behaviour.<br>
PS: just a suggestion for you as newbie. Take a look at "var" keyword. This will make your programing experience much more pleasant imo :)</p>
<br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Oct 26, 2024, 13:18 ArbolOne <<a href="mailto:arbolone@gmail.com">arbolone@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>

  

    
  
  <div style="padding-bottom:1px">
    <p><font face="Helvetica, Arial, sans-serif">openjdk 17.0.13
        2024-10-15<br>
        OpenJDK Runtime Environment (build 17.0.13+11-Debian-2deb12u1)<br>
        OpenJDK 64-Bit Server VM (build 17.0.13+11-Debian-2deb12u1,
        mixed mode, sharing)<br>
        <br>
        public class NamesRecord{<br>
            String id;<br>
            ...<br>
            // Setters and Getters<br>
            public String getId(){<br>
                return <a href="http://this.id" target="_blank" rel="noreferrer">this.id</a>;<br>
            }<br>
        }<br>
        <br>
        // Tres Dorritos Despues<br>
        <br>
        main(){<br>
            // aoe.getAllNames() returns an ArrayList<NamesRecord>
        object containing 13 elements<br>
            // each element has a unique value<br>
            var localArrayList = new
        ArrayList<NamesRecord>(aoe.getAllNames());<br>
            // Display all id values in NamesRecord <=== Only prints
        one id NamesRecord::id value 13 times<br>
            for(NamesRecord mydto : localArrayList){<br>
                Integer pos = 1; <br>
                System.out.print(pos + " ID is : ");<br>
                System.err.print(mydto.getId() );<br>
                pos++; // <== This value does not increment<br>
            }<br>
            <br>
            // Second try, but same result<br>
            for(int i = 10; i != localArrayList.size(); i++){<br>
                System.out.print("\'i\' value is : ");<br>
                System.err.println(i); // <== This value does
        increment<br>
                Integer pos = 1; <br>
                System.out.print(pos + " ID is : ");<br>
                System.err.println(localArrayList.get(i).getId() );<br>
                pos++; // <== This value does not get incremented<br>
            }<br>
            <br>
            // Third try, but the similar result<br>
            // Please note that the value of pos is never incremented
        <==<br>
            NamesRecord[] array = new
        NamesRecord[localArrayList.size()];<br>
                array = localArrayList.toArray(array);<br>
                for(NamesRecord mydto : array){<br>
                    Integer pos = 1;<br>
                    System.out.print(pos + " ID is : ");<br>
                    p.setTimer(1);<br>
                    System.err.println(mydto.getId() );<br>
                    pos++; // <== This value does not get incremented<br>
             }<br>
        }</font></p>
    <p><font face="Helvetica, Arial, sans-serif">Hello.<br>
        When looping through the ArrayList or even the Array[] to
        display the content stored in NamesRecord::id only one value is
        displayed; what I'd like to do is to display all the id values
        stored in the ArrayList or Array[] object.<br>
        However, as documented in the snip above, Java behaviour is not
        what I expected; mind you, I am fairly new in Java.<br>
        So, my question is, what am I doing wrong? <br>
        If there is something wrong, would you point it out and help me
        resolve it, please.<br>
      </font></p>
    <p><font face="Helvetica, Arial, sans-serif">Is it a bug that came
        in the recent update I got from Debian?<br>
        If so, how do I report the bug to OpenJDK?</font></p>
    <p><font face="Helvetica, Arial, sans-serif">Thanks in advance.</font><br>
    </p>
  </div>
  <u></u><u></u>

</blockquote></div>