concept string value in category java

appears as: String values, string value, String values
OCA Java SE 8 Programmer I Certification Guide

This is an excerpt from Manning's book OCA Java SE 8 Programmer I Certification Guide.

Explanation: When it comes to the String class, it’s easy to confuse the methods that accept char or String values as method arguments. For example, the overloaded method indexOf can accept both String and char values to search for a target value in a String. The methods startsWith and endsWith accept only arguments of type String. The method charAt accepts only method arguments of type int. Hence, this method can be passed char values, which are stored as unsigned integer values.

Because a String value can accept underscores, the compiler will compile the previous code. But the runtime will throw an exception stating that an invalid format of value was passed to the method parseInt.

2.5.4. Parsing a string value to a primitive type

To get a primitive data type value corresponding to a string value, you can use the static utility method parseDataType, where DataType refers to the type of the return value. Each wrapper class (except Character) defines a method to parse a String to the corresponding primitive value, as listed in table 2.14.

  • 40