Home Java Character Methods isISOControl() Java Character isISOControl() Method Definition In Java, Character.isISOControl(ch) returns true when the character is an ISO control character : a code from 0x00 to 0x1F or from 0x7F to 0x9F. These are invisible instructions, not printable characters, such as tab, newline, carriage return, bell (0x07), escape (0x1B), and delete (0x7F).
The rule is a fixed numeric range, so unlike most tests it does not depend on the Unicode version. The space (0x20) and the non-breaking space (0xA0) sit just outside the ranges and are not controls.
A static method of java.lang.Character (Java 1.1+): call it on the class, as in Character.isISOControl(...); you do not need a Character object. No import is needed, because java.lang is always available. The int codePoint overload was added in Java 5.
Syntax Pass a char or an int code point.
Character.isISOControl('\n'); // true (0x0A)
Character.isISOControl('\u001B'); // true (escape)
Character.isISOControl(' '); // false (0x20)
Character.isISOControl('\u0085'); // true (0x85, next line) Call What it does Character.isISOControl(c)Is this an invisible control code? if (!Character.isISOControl(c)) out.append(c);Strip control codes from text. Character.isISOControl(c) && !Character.isWhitespace(c)Controls other than tab, newline, and friends.
Overloads: isISOControl(char ch) and isISOControl(int codePoint). Note the capital ISO in the name: isIsoControl does not compile.
Library declarations // java.lang.Character
public static boolean isISOControl(char ch)
public static boolean isISOControl(int codePoint) // since Java 5 Parameters Parameter Description ch (char)The character to test. codePoint (int)The code point to test.
Return Value Return Value Description trueThe value is in 0x00 to 0x1F or 0x7F to 0x9F. falseAny other value.
Compare with Similar Methods Related character groups:
Java Examples 1. Inside and outside the ranges 2. Remove control codes 3. Show controls as escapes Example 1 — Which Characters Are ISO Controls? Test values at both ends of each range and just outside them.
public class CharacterIsIsoControlTable {
public static void main(String[] args) {
char[] chars = {'\u0000', '\t', '\n', '\u001B', ' ', '~', '\u007F', '\u0085', '\u00A0'};
for (char c : chars) {
System.out.println((int) c + " control=" + Character.isISOControl(c));
}
}
} 0 control=true
9 control=true
10 control=true
27 control=true
32 control=false
126 control=false
127 control=true
133 control=true
160 control=false How It Works The first range. NUL (0), tab (9), newline (10), and escape (27) all lie between 0x00 and 0x1F.Printable ASCII in between. The space (32) and the tilde (126) are ordinary characters.The second range. DELETE (127) and NEXT LINE (133) fall between 0x7F and 0x9F; the non-breaking space (160) is just past the end.Example 2 — Strip Terminal Control Codes from a Log Line A log line contains a bell character and an escape code. Remove the control characters and count them.
public class CharacterIsIsoControlStrip {
public static void main(String[] args) {
String line = "OK\u0007 done\u001B[0m";
StringBuilder clean = new StringBuilder();
int removed = 0;
for (char c : line.toCharArray()) {
if (Character.isISOControl(c)) {
removed++;
} else {
clean.append(c);
}
}
System.out.println(clean + " (removed " + removed + ")");
}
} How It Works Two hidden controls. U+0007 is BELL and U+001B is ESCAPE, which starts terminal colour codes such as ESC[0m.Only the controls go. Both fail the else branch and are counted; every printable character, including the space, is copied.Leftovers. The text [0m stays, because only the escape character itself is a control; removing full colour codes needs extra parsing.Example 3 — Print Control Characters as Visible Escapes Turn every control character into a \uXXXX-style text escape so that a log line shows exactly what the string contains.
public class CharacterIsIsoControlEscape {
public static void main(String[] args) {
String s = "A\tB\u0000C";
StringBuilder out = new StringBuilder();
for (char c : s.toCharArray()) {
if (Character.isISOControl(c)) {
String hex = Integer.toHexString(c);
while (hex.length() < 4) {
hex = "0" + hex;
}
out.append("\\u").append(hex);
} else {
out.append(c);
}
}
System.out.println(out);
}
} How It Works Hex with padding. Integer.toHexString gives "9" for the tab and "0" for NUL; the while loop pads both to four digits.A literal backslash. "\\u" in the source is a backslash followed by u. The doubled backslash keeps the compiler from reading it as a Unicode escape.Printable text untouched. A, B, and C are not controls, so they are appended as they are.Frequently Asked Questions Which characters does isISOControl accept? Exactly U+0000 to U+001F and U+007F to U+009F, which are 65 characters in total.
Is the space a control character? No. The space is U+0020, just after the first control range.
Is a tab a control character? Yes. Tab (U+0009), newline (U+000A), and carriage return (U+000D) are ISO controls, and they are also whitespace.
Does isISOControl depend on the Unicode version? No. It is defined by two fixed numeric ranges, so it gives the same answer on every JDK.
How do I remove control characters but keep line breaks? Skip a character only when isISOControl(c) && !Character.isWhitespace(c). That keeps tab, newline, and carriage return.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
13 people found this page helpful
Helpful Share Copy link Suggestion