![escape sequences java escape sequences java](https://justtechreview.com/wp-content/uploads/2019/11/Java-Escape-Sequences-With-Program-Example.jpg)
When the pattern to be matched contains a sequence of characters identical to one of the Java escape sequences- "\" and "n", for example-the Java compiler treats that portion of the string as a Java escape sequence and transforms the sequence into an actual newline character. A string literal used for pattern matching is compiled into an instance of the Pattern type. When representing SQL statements in Java string literals, each escape sequence must be preceded by an extra backslash for correct interpretation.Īs another example, consider the Pattern class used in performing regular expression-related tasks.
![escape sequences java escape sequences java](https://i.ytimg.com/vi/8EOgVQbqWsY/hqdefault.jpg)
SQL statements may require escape sequences (for example, sequences containing \t, \n, \r) in certain cases, such as when storing raw text in a database. The character and string escape sequences allow for the representation of some nongraphic characters as well as the single quote, double quote, and backslash characters in character literals (§3.10.4) and string literals (§3.10.5).Ĭorrect use of escape sequences in string literals requires understanding how the escape sequences are interpreted by the Java compiler as well as how they are interpreted by any subsequent processor, such as a SQL engine. According to the Java Language Specification (JLS), §3.10.6, "Escape Sequences for Character and String Literals" , Many classes allow inclusion of escape sequences in character and string literals examples include as well as classes that support XML- and SQL-based actions by passing string arguments to methods.