object to string java code example

Example 1: string to double java

public class stringtodouble {
	public static void main(String args) {
    	String string = "1.23";
      	double decimal = Double.parseDouble(string);
    }
}

Example 2: how to convert an object into string with different fields in java

String convertedToString = String.valueOf(Object);  //method 1

String convertedToString = "" + Object;   //method 2

String convertedToString = Object.toString();  //method 3

Example 3: array to string java

char[] charArray = new char[] {'b','u','z','z'};

String answer = new String(charArray);