Skip to main content

Posts

Showing posts from September, 2017

How to convert String into primitive data types and primitive data types into String

#Topic-7 Previous topic (6) we have discussed about Wrapper class, auto-boxing, UN-boxing and other related topics. If you have not gone through that topic, click this link   Wrapper class, auto-boxing, UN-boxing in Java? In this section we will discuss about How to convert String into primitive data types and primitive data types into String. How to convert String into primitive data type: Note: value should be compatible to destination type (we can’t convert “java” into int)   //1st way Example of convert String to Integer:  String str1 = "5"; int result = Integer.parseInt(str1); // Using Integer.parsrInt() System.out.println(result); Example of convert String to Double: String str=”125”; double a1=Double.parseDouble(str); System.out.println(a1);  Example of convert String to Boolean: String a=”true”; boolean a=Boolean.parseBoolean(a);  System.out.println(a);   Example of convert...