-3
public class ArrayManipulations {

    public static void main(String[] args) {

        String name = num.toString();
        System.out.println(name); // want to convert this back to int 
        System.out.println(num.getClass().getName() + '@' + Integer.toHexString(num.hashCode()));
}

}

Now i want to convert the name back to integer. is it possible???

SatyaTNV
  • 4,119
  • 3
  • 14
  • 31
shashank tyagi
  • 379
  • 2
  • 7

5 Answers5

2

Yes.

int i = Integer.parseInt(name);
emlai
  • 39,703
  • 9
  • 98
  • 145
2

Yes you can

Return an Object Integer :

Integer var = Integer.valueOf("0");

This method returns the relevant Number Object holding the value of the argument passed. The argument can be a primitive data type, String, etc.

Return a primitive int :

int var = Integer.parseInt("0");

This method is used to get the primitive data type of a certain String. parseXxx() is a static method and can have one argument or two.

Wael Sakhri
  • 377
  • 1
  • 8
0

If you want to convert String to int, you use:

int intNum = Integer.parseInt(name); //name is variable that you want to change back to int
Thomas
  • 84,542
  • 12
  • 116
  • 151
Jure
  • 797
  • 7
  • 24
0

The Integer class provides the following method for this task:

Integer.parseInt(String s);
nuke
  • 530
  • 3
  • 11
0

Yes.

Integer.parseInt(Integer.toString(3));

should do the trick. More in the Java Documentation.

ZakC
  • 469
  • 3
  • 11