Skip to main content

Posts

Showing posts from 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...

Wrapper class ,auto boxing and unboxing in Java

#Topic-6 Previous topic (5) we have discussed about Variables and Data Types in Java, we have gone through various data types and literals. If you have not gone through that topic, click this link What are the Variables and Data types using in Java? In this section we will discuss about Wrapper class, auto-boxing, UN-boxing and many more! Wrapper class in Java Each of Java's eight primitive data types has a class dedicated to it. These are known as wrapper classes because they "wrap" the primitive data type into an object of that class. The wrapper classes are part of the java.lang package, which is imported by default into all Java programs.  Wrapper class in java are the Object representation of eight primitive types in java. All the wrapper classes in java are  immutable and final. Java  auto boxing and UN-boxing allows easy conversion between primitive types and their corresponding wrapper classes in java programs.All the wrapper classes (Integer, ...