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

How to set the permissions to a file in java?

0 Answers  


What happens if we don’t override run method ?

0 Answers  


Difference between the String and StringBuffer classes?

3 Answers  


Differences between GridLayout and GridBagLayout?

1 Answers  


Difference between start() and run() method of thread class?

0 Answers  






What is return data type?

0 Answers  


How will you reverse a singly-link list?

0 Answers   Akamai Technologies,


String Reverse in Java...!

5 Answers  


What is the use of a conditional inclusion statement in Java ?

0 Answers   Global Logic,


How the elements are organized in GridBagLayout?

1 Answers  


I have one POJO class(Java bean class), it has two variables for that it has setters and getters. Now i have created two objects for that class and i have set the data for those variables through this two objects. Now question is i want check whether those two objects have same data or not, for this write a program? Thanks, Bose.

2 Answers   Oracle,


why Java does not support multiple inheritances?

0 Answers   Aspire,


Categories