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);
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!
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.
if (fieldValue instanceof String)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With