Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Value to Integer [duplicate]

How to get value of an object and store it in variable int? In string I do this:

String k = s_extend.getValue().toString();

How about in int?

like image 386
general_bearbrand Avatar asked Dec 13 '13 01:12

general_bearbrand


1 Answers

You can use Integer.valueOf() or Integer.parseInt(); unless there's more to your question that would be something like this -

public static void main(String[] args) {
  String str = "1";
  int a = Integer.valueOf(str);                 // java.lang.Integer return(ed)
  int b = Integer.parseInt(str);                // primitive (int) return(ed)
  System.out.printf("a = %d, b = %d\n", a, b);
}

On my machine, running this gives

a = 1, b = 1
like image 155
Elliott Frisch Avatar answered Sep 24 '22 23:09

Elliott Frisch