How to convert String into primitive datatype.

Answers were Sorted based on User's Feedback



How to convert String into primitive datatype...

Answer / vikki

using parseInt() method for example

//String to primitive types
int iVal = Integer.parseInt(str);
long lVal = Long.parseLong(str);
float fVal = Float.parseFloat(str);
double dVal = Double.parseDouble(str);

Is This Answer Correct ?    32 Yes 5 No

How to convert String into primitive datatype...

Answer / akshya kumar

using the wrapper classes, by using the function in
following way:

int i_var = Integer.parseInt(string_var); //and as in
answer #2

Integer, Float, Long are wrapper classes predefined in JAVA
with methods parseInt(), parseFloat etc respectively.

Is This Answer Correct ?    4 Yes 0 No

How to convert String into primitive datatype...

Answer / akshya kumar

we can also use valueOf method of wrapper classes like:

int i_var = Integer.valueOf(string_var);
float f_var = Float.valueOf(string_vatr);

Is This Answer Correct ?    4 Yes 1 No

How to convert String into primitive datatype...

Answer / niranjan sahoo

by using parsing methods of the respective primitive type like if we want to convert into int then use parseint() , if float then use parsefloat()...

Is This Answer Correct ?    3 Yes 3 No

How to convert String into primitive datatype...

Answer / nilesh

by using parseing methode of String class

Is This Answer Correct ?    0 Yes 7 No

How to convert String into primitive datatype...

Answer / srinu

convert int to string

Is This Answer Correct ?    5 Yes 13 No

Post New Answer

More Core Java Interview Questions

What is thread pool in java with example?

0 Answers  


How the threads are synchronized?

2 Answers   BMC, CTS,


What is array class in java?

0 Answers  


What is callablestatement? How you can call stored procedure to pass in parameter?

0 Answers  


Differentiate between class and structure.

0 Answers   Amdocs, Motorola,






What is the alternate of 'Inheritance' ?

4 Answers   CybAge, HCL,


how to call One constructor from another;

10 Answers   Innodata Isogen,


When is the finally clause of a try-catch-finally statement executed?

0 Answers  


What is complexity in java?

0 Answers  


What is treemap in java?

0 Answers  


What is a buffer in java?

0 Answers  


Can a class have 2 constructors?

0 Answers  


Categories