-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,137
  • 3
  • 15
  • 31
shashank tyagi
  • 484
  • 3
  • 7

5 Answers5

2

Yes.

int i = Integer.parseInt(name);
Emil Laine
  • 41,598
  • 9
  • 101
  • 157
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
  • 397
  • 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
  • 87,414
  • 12
  • 119
  • 157
Jure
  • 799
  • 6
  • 25
0

The Integer class provides the following method for this task:

Integer.parseInt(String s);
Lukas Maurer
  • 540
  • 3
  • 11
0

Yes.

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

should do the trick. More in the Java Documentation.

ZakC
  • 479
  • 3
  • 11