Dec 11

Java example to convert String to Boolean in java?

public class StringToBooleanDemo {

	public static void main(String[] args) {

		//Create a new string object and assign value true to str

		String str="true";

		//Create a new Boolean Object
		Boolean bool=new Boolean(str);

		//Print the value in console
		System.out.println(bool);

		//Use Boolean class static method valueOf which will convert string to
		//Boolean and return Boolean object

		Boolean bool1=Boolean.valueOf(str);

		//Print the value in console
		System.out.println(bool1);

	}

 

Dec 10

How to convert String to BigDecimal in java?

To convert String to BigDecimal in java use BigDecimal Constructor.The below example demonstrates how to convert String to BigDecimal in java.

import java.math.BigDecimal;

public class StringToBigDecimal {

	public static void main(String[] args) {

		String string="100.00";
		BigDecimal bigDecimal=new BigDecimal(string);
		System.out.println(" Printing BigDecimal Value "+bigDecimal);

	}

}

 

Output :

Printing BigDecimal Value 100.00