Skip to content

Commit 132818d

Browse files
authored
[BAEL-5661] Integer.toString(int i) vs String.valueOf(int i) (eugenp#12606)
* Initial commit for Object copy in Java * review comments commit for Object copy in Java * Initial commit for parseInt vs valueOf java * Review comments commit for parseInt vs valueOf java * Modify readme * review comments * build failure * build failure retry * build failure retry remove parseInt(java.lang.String,int,int,int) * build failure add comment * change examples * review comments * review comments 2 * review comments 3 * Initial commit for get current stacktrace * Remove old files * Name updates * Jenkins error * changes to file name * Review comments * Create unit test file * Remove unnecessary files * Update package name
1 parent 778691a commit 132818d

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

core-java-modules/core-java-string-conversions-2/src/test/java/com/baeldung/inttostring/IntToStringUnitTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung.chararraytostring;
1+
package com.baeldung.inttostring;
22

33
import static org.junit.Assert.assertEquals;
44

@@ -23,7 +23,8 @@ public void whenValidIntIsPassed_thenShouldConvertToValidString() {
2323
@Test(expected = NullPointerException.class)
2424
public void whenNullIntegerObjectIsPassed_thenShouldThrowException() {
2525
Integer i = null;
26-
System.out.println(String.valueOf(i)); // it prints "null"
27-
System.out.println(i.toString());
26+
// NOTE: primitive int can never be null, we are checking this example to check in what case the exception is thrown by these methods.
27+
System.out.println(String.valueOf(i)); // prints "null" as the call goes to String.valueOf(Object obj) method
28+
System.out.println(i.toString()); // throws NPE
2829
}
2930
}

0 commit comments

Comments
 (0)