Java Convert String to Object

We can convert String to Object in java with assignment operator. Each class is internally a child class of Object class. So you can assign string to Object directly.

Java Convert String to Object

You can also convert String to Class type object using Class.forName() method.

Java String to Object Example

Let's see the simple code to convert String to Object in java.

Let's see the simple code to convert String to Object in java.

Test it Now

Output:

hello

Java String to Class object Example

Let's see the simple code to convert String to Class object in java using Class.forName() method. The Class.forName() method returns the instance of Class class which can be used to get the metadata of any class.

Test it Now

Output:

Class name: java.lang.String
Super class name: java.lang.Object




Contact US

Email:[email protected]

Java String to Object
10/30