Java doesn't have such kind of method, but you can check whether a string can be represented properly in a specific character encoding, by trying encoding/decoding.
For example, you can make your own string.canBeConvertedToStringEncoding
equivalent as follows:
import java.io.UnsupportedEncodingException;
class Main {
public static void main(String[] args) throws UnsupportedEncodingException {
if (canBeConvertedToStringEncoding("abc", "ISO-8859-1")) {
System.out.println("can be converted");
} else {
System.out.println("cannot be converted");
}
if (canBeConvertedToStringEncoding("あいう", "ISO-8859-1")) {
System.out.println("can be converted");
} else {
System.out.println("cannot be converted");
}
}
public static boolean canBeConvertedToStringEncoding(String target, String encoding) throws UnsupportedEncodingException {
String to = new String(target.getBytes(encoding), encoding);
return target.equals(to);
}
}