In order to check whether the string of characters are ASCII or not. Which one of the below is better choice ?
java.nio.charset.Charset.forName("US-ASCII").newEncoder().canEncode("Desire character string to be checked")
or- Convert the String to character array and use :
org.apache.commons.lang.CharUtils.isAscii()
method to check whether ASCII.
What are their differences, and which one is good performance wise. I know for the second option there is additional step of converting string to the character array first and then, need to check each character.