How To Convert C# int To java Integer (java.lang.Integer) [Resolved]

Posted by Kasani007 under C# on 12/21/2015 | Points: 10 | Views : 906 | Status : [Member] | Replies : 4
How To Convert C# int To java Integer (java.lang.Integer) ?




Responses

Posted by: Rajnilari2015 on: 12/21/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
@Kasani007 Sir, Java.lang.Integer.valueOf(int x) returns a Integer instance that represents the specified int value x. e.g.

import java.lang.*;


public class test {

public static void main(String[] args) {

int x = 100;
System.out.println(Integer.valueOf(x));
}
}


After compilation and execution

D:\Java\jdk1.8.0_45\bin>javac test.java


D:\Java\jdk1.8.0_45\bin>java test
100


So in your program instead of java.lang.Integer.valueOf(empId.ToString()); , you can safely remove .ToString() and do java.lang.Integer.valueOf(empId);

Hope this helps.

--
Thanks & Regards,
RNA Team

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 12/21/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
What about
Integer.valueOf
which is under Java.lang.Integer package ?

--
Thanks & Regards,
RNA Team

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kasani007 on: 12/21/2015 [Member] Starter | Points: 25

Up
0
Down
java.lang.Integer.valueOf(string) , it takes only string as paramenter,

Here I had Converted my int value to string and again i had used that string value in java.lang.Integer.valueOf() , its well and good... but two times conversion is taking , one is from c# integer to c# string and again c#string to java Integer i.e.,

java.lang.Integer.valueOf(empId.ToString());

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amatya on: 2/6/2016 [Member] Bronze | Points: 25

Up
0
Down
Basic C# Interview Questions Visit
http://aditya-aditya200.blogspot.in/2016/02/c-interviews-questions.html


Feel free to share informations 9731764134
Thanks

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response