Temp. variable or method calls? And literal or equivalent variable?
<pre><code> private static final Group[] toGroups (String string)
    {
        int     partialGroupSize = string.length() % GROUP_SIZE;
        boolean hasPartialGroup  = partialGroupSize != 0;
        int     nGroupOffset     = hasPartialGroup ? 1 : 0;
        int     nGroup           = string.length() / GROUP_SIZE + nGroupOffset;
        Group[] groups           = new Group[nGroup];
        for (int i = 0; i &lt; nGroup; i++) {
            boolean isFirstGroup = i == 0;
            int beginIndex = isFirstGroup ? i :
                             GROUP_SIZE * (i - nGroupOffset) + partialGroupSize;
            int   endIndex = isFirstGroup &amp;&amp; hasPartialGroup ?
                             beginIndex + partialGroupSize :
                             beginIndex + GROUP_SIZE;
            groups[i] = new Group(Integer.parseInt(string.substring(beginIndex,
                                                                      endIndex)));
        }
        return groups;
    }
</code></pre>

<p>My first question is one that I found different discussions about, but I still don't know what I should do.<br>
The method <code>toGroups</code> is only called once in the program, therefore <code>.length()</code> is only called twice on <code>string</code> of <code>toGroups</code> in the program. So with regards to performance and readability, should I replace <code>string.length()</code> with <code>length</code> where <code>int length = string.length();</code>?<br>
Id est:</p>

<pre><code>int     length           = string.length();
int     partialGroupSize = length % GROUP_SIZE;
boolean hasPartialGroup  = partialGroupSize != 0;
int     nGroupOffset     = hasPartialGroup ? 1 : 0;
int     nGroup           = length / GROUP_SIZE + nGroupOffset;
</code></pre>

<p>My second question is: within the <code>for</code> loop, given that when the predicate of the <code>beginIndex</code> conditional assignment, <code>isFirstGroup</code>, is <code>true</code>, <code>i</code> must be <code>0</code>; should I replace the consequent of the <code>beginIndex</code> conditional with a literal <code>0</code>?<br>
Id est:</p>

<pre><code>int beginIndex = isFirstGroup ? 0 :
                 GROUP_SIZE * (i - nGroupOffset) + partialGroupSize;
</code></pre>

<p>I reason that because the consequent of <code>beginIndex</code> is always <code>0</code>, using the equivalent <code>i</code> iterator creates an ambiguity in the constancy/variableness of the consequent.</p>
