Learn Java Programming

Java Basics

java.lang.StringIndexOutOfBoundsException: String index out of range

The java.lang.StringIndexOutOfBoundsException: String index out of range arises when the string index is either negative, or larger than the length of the string, i.e. out of range The java string index range should be in between 0 and the size of the string. The java String.charAt() method returns the character

java.io.UnsupportedEncodingException example

The java.io.UnsupportedEncodingException occurs when an unsupported character encoding scheme is used in java strings or bytes. The java String getBytes method converts the requested string to bytes in the specified encoding format. If the java does not support the encoding format, the method String getBytes throws java.io.UnsupportedEncodingException with the encoding

How to resolve java.util.regex.PatternSyntaxException at String.matches, String.split, String.replaceAll

The java.util.regex.PatternSyntaxException is thrown when the regular expression – regex pattern is not correct. The java String matches method checks the given string with the specified regular expression. If the java string matches the regular expression, it will return true, otherwise it will return false. The java exception java.util.regex.PatternSyntaxException is

java.util.regex.PatternSyntaxException: Dangling meta character ‘*’ near index 0

The java exception java.util.regex.PatternSyntaxException: Dangling meta character ‘*’ near index 0 happens when the string is matched by the regular expression meta character such as “*”, “+”, “?”. In a search string, the regular expression meta characters (“*”, “+”, “?”) must escape. The regular expression contains meta characters such as

java.util.regex.PatternSyntaxException: Unclosed character class near index 0

The java exception java.util.regex.PatternSyntaxException: Unclosed character class near index 0 happens when the string is matched by the regular expression special character ‘[’ open square bracket. In a search string, the special character (open square bracket) must escape. The regular expression uses the “[ ]” square bracket to match one

java.util.regex.PatternSyntaxException: Unclosed group near index 1

The regular expression uses the “( )” round bracket to identify the matching groups in a string. The matched character in the round bracket identified as a match group in a string. The exception “java.util.regex.PatternSyntaxException: Unclosed group near index” will be thrown if the open round bracket is available without

java.util.regex.PatternSyntaxException: Unmatched closing ‘)’

The java exception java.util.regex.PatternSyntaxException: Unmatched closing ‘)’ happens when the string is matched by the regular expression special character ‘)’ closing parentheses. In a search string, the character “(” and “)” and “{” and “}” are special characters in regular expression. these dialect characters have to be escaped. You need to escape ‘(‘ and ‘)’ with ‘\\(‘ and ‘\\)’ The

java.util.regex.PatternSyntaxException: Unexpected internal error near index 1

The backward slash “\” is used to escape characters in the java string. If a string contains a backward slash “\”, a escape character is added along with backward slash “\”. For example, a String “Yawin\tutor” is created as “Yawin\\tutor” in java. In regular expression if you use single backward

java.util.regex.PatternSyntaxException: Illegal repetition

The java.util.regex.PatternSyntaxException: Illegal repetition exception occurs when the regex dialects ‘{’ and ‘}’ are not used for repetition qualifier. In java, the regular expression dialects ‘{‘ and ‘}’ have special meaning. They are the opening and closing tokens for the {m, n} repetition quantifier where m and n are integers.

java.util.regex.PatternSyntaxException: Unclosed counted closure near index

The java exception java.util.regex.PatternSyntaxException: Unclosed counted closure near index occurs when a string matches by the regular expression special character ‘{’ open curly bracket without close curly bracket. In a search string, the special character (close curly bracket) must be added. The regular expression uses the “{ }” curly bracket