I want to convert a string say "98989" into an integer without using any library functions in java. Give fastest way to do it and explain why your method is best.
String str = "1234"; int num = Integer.parseInt(str);
To convert a number into a string, use:
int num = 1234; String str = String.valueOf(num);
Integer.valueOf is fastest because it uses cached instance. So if there already exists a Integer in pool with value 98989, that will be returned instead of creating new Integer instance.
Check this for details. http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#valueOf(int)
I need help in writing the code where I enter the input in which each char is followed by its occurrence and output should be absolute string.
Example Input a10b5c4 Output aaaaaaaaaabbbbbcccc