Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cast object to string check if valid

Im using the following code that the fieldValue can have simple property , there is a way to check before im doing this code if fieldValue is not contain object that cannot be cast to string ?to avoid dump

keyVal.put(fieldName, (String) fieldValue);
like image 918
James Berners Avatar asked Jun 10 '13 17:06

James Berners


People also ask

How do you check if an object is a string?

Use the typeof operator to check if a variable is a string, e.g. if (typeof variable === 'string') . If the typeof operator returns "string" , then the variable is a string. In all other cases the variable isn't a string. Copied!

How do you turn an object into a string?

We can convert Object to String in java using toString() method of Object class or String. valueOf(object) method. You can convert any object to String in java whether it is user-defined class, StringBuilder, StringBuffer or anything else.


1 Answers

if (fieldValue instanceof String)
like image 71
SLaks Avatar answered Nov 15 '22 01:11

SLaks