[BAEL-5661] Integer.toString(int i) vs String.valueOf(int i) (#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
This commit is contained in:
sdhiray7 2022-08-17 21:04:12 +05:30 committed by GitHub
parent 72409da627
commit 087a50b2e7
1 changed files with 4 additions and 3 deletions

View File

@ -1,4 +1,4 @@
package com.baeldung.chararraytostring;
package com.baeldung.inttostring;
import static org.junit.Assert.assertEquals;
@ -23,7 +23,8 @@ public class IntToStringUnitTest {
@Test(expected = NullPointerException.class)
public void whenNullIntegerObjectIsPassed_thenShouldThrowException() {
Integer i = null;
System.out.println(String.valueOf(i)); // it prints "null"
System.out.println(i.toString());
// NOTE: primitive int can never be null, we are checking this example to check in what case the exception is thrown by these methods.
System.out.println(String.valueOf(i)); // prints "null" as the call goes to String.valueOf(Object obj) method
System.out.println(i.toString()); // throws NPE
}
}