String result = "";
try{
int value = Integer.parseInt(a)+Integer.parseInt(b);
result = ""+value;
}catch(NumberFormatException ex){
//either a or b is not a number
result = "Invalid input";
}
MyStringSum.show(null,a+b);
I am using Wrapper Class but i want to sum two String values without using
Wrapper Class , can i do this?
You should not worry about the efficiency of your implementation, because it is not using any wrapper objects.
java.lang.Integer
plays several roles:
MIN_VALUE
and MAX_VALUE
,int
s by providing class methods for parsing and manipulating them, andObject
wrappers for primitive int
s, and providing instance methods for it.Because you use only parse(...)
, which is a class method, your code uses the class in its capacity #2, ignoring the #1 and #3. In other words, you are not using Integer
in its "wrapper for int
" capacity.