Java 8 Iterator stream filter NoSuchElementException
<pre><code>    public static double getAttackSpeed(ItemStack item) {
    Attributes ab = new Attributes(item);
    for(Attributes.Attribute attribute : ab.values())
        Flawlord.log(attribute.getName());
    return FlawlordHelper.stream(ab.values()).filter(a -&gt; a.getAttributeType().equals(Attributes.AttributeType.GENERIC_ATTACK_SPEED)).findFirst().get().getAmount();
}
</code></pre>

<p>this doesnt work</p>

<pre><code>    public static int getDamage(ItemStack item) {
    Attributes ab = new Attributes(item);
    int dmg = 0;
    for(Attributes.Attribute attribute : ab.values())
        if (attribute.getAttributeType() == Attributes.AttributeType.GENERIC_ATTACK_DAMAGE)
            dmg = (int) attribute.getAmount();
    return dmg;
}
</code></pre>

<p>this works</p>

<p>hello. can someone explain to me why the latter works, but the first not? maybe im just not getting it, idk. i think perhaps .equals() doesnt work here?</p>

<p>if i use the first one with lambda, i get an exception "NoSuchElementException: No value present".</p>