How to convert a String to Integer? [closed]

-5

How do I convert a value of type string that needs to be stored in a variable that is of type int ? Here are some conversion codes which is the most appropriate to use for this conversion?

A.a = Integer.valueOf("10")
B.a = int.Parse("10")
C.a = Convert.Numeric("Macedo")
D.a = Convert.ToNumeric("10")
E.a = int.Convert.valueOf("Macedo")
    
asked by anonymous 19.10.2016 / 01:57

1 answer

2

Java provides the following method:

int one = Integer.parseInt("1"); // Retorna um tipo primitivo (int)

This method takes a string and converts it to an integer, just like you need it.

Integer one = oneInteger.valueOf("10"); // Retorna um Objecto Integer
int.parse("10"); // Não existe porque um tipo primitivo não pode ter métodos associados

As for the remaining examples, these methods simply do not exist.

    
19.10.2016 / 15:38