java - Why am i NOT getting null pointer exception in this case while adding null to a list and sorting it -
whenever I change the condition to == 2 or i == 3, I always get NPE but 5 Not in the case? I do not have any more details to add a question. I think the self explanation is
import java.util.ArrayList; Import java.util.Collections; Import java.util.list; Import java.util.Random; Public category test {public static zero major (string terms []) exception {list & lt; X & gt; Arr = new arreelist & lt; X & gt; (); For (int i = 0; i <5; i ++) {arr.add (new x (i)); If (i == 5) {arr.add (tap); }} collection. Support (AR); (Xx: arr) {System.out.println (x.i); }}} Class X applies Comparable {public int i; Public X (Int i2) {i = i2; } To compare override public int (object o) {returns new random (). NextInt (10) -5; }}
This loop only for i
4 So, when you i == 5
Comments
Post a Comment