Class Ascii
0x00 through
0x7F), and to strings containing such characters.
ASCII utilities also exist in other classes of this package:
- StandardCharsets.US_ASCIIspecifies the- Charsetof ASCII characters.
- CharMatcher.ascii()matches ASCII characters and provides text processing methods which operate only on the ASCII characters of a string.
- Since:
- 7.0
- Author:
- Catherine Berry, Gregory Kick
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final byteAcknowledge: A communication control character transmitted by a receiver as an affirmative response to a sender.static final byteBell ('\a'): A character for use when there is a need to call for human attention.static final byteBackspace ('\b'): A format effector which controls the movement of the printing position one printing space backward on the same printing line.static final byteCancel: A control character used to indicate that the data with which it is sent is in error or is to be disregarded.static final byteCarriage Return ('\r'): A format effector which controls the movement of the printing position to the first printing position on the same printing line.static final byteDevice Control 1.static final byteDevice Control 2.static final byteDevice Control 3.static final byteDevice Control 4.static final byteDelete: This character is used primarily to "erase" or "obliterate" erroneous or unwanted characters in perforated tape.static final byteData Link Escape: A communication control character which will change the meaning of a limited number of contiguously following characters.static final byteEnd of Medium: A control character associated with the sent data which may be used to identify the physical end of the medium, or the end of the used, or wanted, portion of information recorded on a medium.static final byteEnquiry: A communication control character used in data communication systems as a request for a response from a remote station.static final byteEnd of Transmission: A communication control character used to indicate the conclusion of a transmission, which may have contained one or more texts and any associated headings.static final byteEscape: A control character intended to provide code extension (supplementary characters) in general information interchange.static final byteEnd of Transmission Block: A communication control character used to indicate the end of a block of data for communication purposes.static final byteEnd of Text: A communication control character used to terminate a sequence of characters started with STX and transmitted as an entity.static final byteForm Feed ('\f'): A format effector which controls the movement of the printing position to the first pre-determined printing line on the next form or page.static final byteFile Separator: These four information separators may be used within data in optional fashion, except that their hierarchical relationship shall be: FS is the most inclusive, then GS, then RS, and US is least inclusive.static final byteGroup Separator: These four information separators may be used within data in optional fashion, except that their hierarchical relationship shall be: FS is the most inclusive, then GS, then RS, and US is least inclusive.static final byteHorizontal Tabulation ('\t'): A format effector which controls the movement of the printing position to the next in a series of predetermined positions along the printing line.static final byteLine Feed ('\n'): A format effector which controls the movement of the printing position to the next printing line.static final charThe maximum value of an ASCII character.static final charThe minimum value of an ASCII character.static final byteNegative Acknowledge: A communication control character transmitted by a receiver as a negative response to the sender.static final byteAlternate name forLF.static final byteNull ('\0'): The all-zeros character which may serve to accomplish time fill and media fill.static final byteRecord Separator: These four information separators may be used within data in optional fashion, except that their hierarchical relationship shall be: FS is the most inclusive, then GS, then RS, and US is least inclusive.static final byteShift In: A control character indicating that the code combinations which follow shall be interpreted according to the standard code table.static final byteShift Out: A control character indicating that the code combinations which follow shall be interpreted as outside of the character set of the standard code table until a Shift In character is reached.static final byteStart of Heading: A communication control character used at the beginning of a sequence of characters which constitute a machine-sensible address or routing information.static final byteSpace: A normally non-printing graphic character used to separate words.static final byteAlternate name forSP.static final byteStart of Text: A communication control character which precedes a sequence of characters that is to be treated as an entity and entirely transmitted through to the ultimate destination.static final byteSubstitute: A character that may be substituted for a character which is determined to be invalid or in error.static final byteSynchronous Idle: A communication control character used by a synchronous transmission system in the absence of any other character to provide a signal from which synchronism may be achieved or retained.static final byteUnit Separator: These four information separators may be used within data in optional fashion, except that their hierarchical relationship shall be: FS is the most inclusive, then GS, then RS, and US is least inclusive.static final byteVertical Tabulation ('\v'): A format effector which controls the movement of the printing position to the next in a series of predetermined printing lines.static final byteTransmission off.static final byteTransmission On: Although originally defined as DC1, this ASCII control character is now better known as the XON code used for software flow control in serial communications.
- 
Method SummaryModifier and TypeMethodDescriptionstatic booleanequalsIgnoreCase(CharSequence s1, CharSequence s2) Indicates whether the contents of the given character sequencess1ands2are equal, ignoring the case of any ASCII alphabetic characters between'a'and'z'or'A'and'Z'inclusive.static booleanisLowerCase(char c) Indicates whethercis one of the twenty-six lowercase ASCII alphabetic characters between'a'and'z'inclusive.static booleanisUpperCase(char c) Indicates whethercis one of the twenty-six uppercase ASCII alphabetic characters between'A'and'Z'inclusive.static chartoLowerCase(char c) If the argument is an uppercase ASCII character, returns the lowercase equivalent.static StringtoLowerCase(CharSequence chars) Returns a copy of the input character sequence in which all uppercase ASCII characters have been converted to lowercase.static StringtoLowerCase(String string) Returns a copy of the input string in which all uppercase ASCII characters have been converted to lowercase.static chartoUpperCase(char c) If the argument is a lowercase ASCII character, returns the uppercase equivalent.static StringtoUpperCase(CharSequence chars) Returns a copy of the input character sequence in which all lowercase ASCII characters have been converted to uppercase.static StringtoUpperCase(String string) Returns a copy of the input string in which all lowercase ASCII characters have been converted to uppercase.static Stringtruncate(CharSequence seq, int maxLength, String truncationIndicator) Truncates the given character sequence to the given maximum length.
- 
Field Details- 
NULpublic static final byte NULNull ('\0'): The all-zeros character which may serve to accomplish time fill and media fill. Normally used as a C string terminator.Although RFC 20 names this as "Null", note that it is distinct from the C/C++ "NULL" pointer. - Since:
- 8.0
- See Also:
 
- 
SOHpublic static final byte SOHStart of Heading: A communication control character used at the beginning of a sequence of characters which constitute a machine-sensible address or routing information. Such a sequence is referred to as the "heading." An STX character has the effect of terminating a heading.- Since:
- 8.0
- See Also:
 
- 
STXpublic static final byte STXStart of Text: A communication control character which precedes a sequence of characters that is to be treated as an entity and entirely transmitted through to the ultimate destination. Such a sequence is referred to as "text." STX may be used to terminate a sequence of characters started by SOH.- Since:
- 8.0
- See Also:
 
- 
ETXpublic static final byte ETXEnd of Text: A communication control character used to terminate a sequence of characters started with STX and transmitted as an entity.- Since:
- 8.0
- See Also:
 
- 
EOTpublic static final byte EOTEnd of Transmission: A communication control character used to indicate the conclusion of a transmission, which may have contained one or more texts and any associated headings.- Since:
- 8.0
- See Also:
 
- 
ENQpublic static final byte ENQEnquiry: A communication control character used in data communication systems as a request for a response from a remote station. It may be used as a "Who Are You" (WRU) to obtain identification, or may be used to obtain station status, or both.- Since:
- 8.0
- See Also:
 
- 
ACKpublic static final byte ACKAcknowledge: A communication control character transmitted by a receiver as an affirmative response to a sender.- Since:
- 8.0
- See Also:
 
- 
BELpublic static final byte BELBell ('\a'): A character for use when there is a need to call for human attention. It may control alarm or attention devices.- Since:
- 8.0
- See Also:
 
- 
BSpublic static final byte BSBackspace ('\b'): A format effector which controls the movement of the printing position one printing space backward on the same printing line. (Applicable also to display devices.)- Since:
- 8.0
- See Also:
 
- 
HTpublic static final byte HTHorizontal Tabulation ('\t'): A format effector which controls the movement of the printing position to the next in a series of predetermined positions along the printing line. (Applicable also to display devices and the skip function on punched cards.)- Since:
- 8.0
- See Also:
 
- 
LFpublic static final byte LFLine Feed ('\n'): A format effector which controls the movement of the printing position to the next printing line. (Applicable also to display devices.) Where appropriate, this character may have the meaning "New Line" (NL), a format effector which controls the movement of the printing point to the first printing position on the next printing line. Use of this convention requires agreement between sender and recipient of data.- Since:
- 8.0
- See Also:
 
- 
NL
- 
VTpublic static final byte VTVertical Tabulation ('\v'): A format effector which controls the movement of the printing position to the next in a series of predetermined printing lines. (Applicable also to display devices.)- Since:
- 8.0
- See Also:
 
- 
FFpublic static final byte FFForm Feed ('\f'): A format effector which controls the movement of the printing position to the first pre-determined printing line on the next form or page. (Applicable also to display devices.)- Since:
- 8.0
- See Also:
 
- 
CRpublic static final byte CRCarriage Return ('\r'): A format effector which controls the movement of the printing position to the first printing position on the same printing line. (Applicable also to display devices.)- Since:
- 8.0
- See Also:
 
- 
SOpublic static final byte SOShift Out: A control character indicating that the code combinations which follow shall be interpreted as outside of the character set of the standard code table until a Shift In character is reached.- Since:
- 8.0
- See Also:
 
- 
SIpublic static final byte SIShift In: A control character indicating that the code combinations which follow shall be interpreted according to the standard code table.- Since:
- 8.0
- See Also:
 
- 
DLEpublic static final byte DLEData Link Escape: A communication control character which will change the meaning of a limited number of contiguously following characters. It is used exclusively to provide supplementary controls in data communication networks.- Since:
- 8.0
- See Also:
 
- 
DC1public static final byte DC1Device Control 1. Characters for the control of ancillary devices associated with data processing or telecommunication systems, more especially switching devices "on" or "off." (If a single "stop" control is required to interrupt or turn off ancillary devices, DC4 is the preferred assignment.)- Since:
- 8.0
- See Also:
 
- 
XONpublic static final byte XONTransmission On: Although originally defined as DC1, this ASCII control character is now better known as the XON code used for software flow control in serial communications. The main use is restarting the transmission after the communication has been stopped by the XOFF control code.- Since:
- 8.0
- See Also:
 
- 
DC2public static final byte DC2Device Control 2. Characters for the control of ancillary devices associated with data processing or telecommunication systems, more especially switching devices "on" or "off." (If a single "stop" control is required to interrupt or turn off ancillary devices, DC4 is the preferred assignment.)- Since:
- 8.0
- See Also:
 
- 
DC3public static final byte DC3Device Control 3. Characters for the control of ancillary devices associated with data processing or telecommunication systems, more especially switching devices "on" or "off." (If a single "stop" control is required to interrupt or turn off ancillary devices, DC4 is the preferred assignment.)- Since:
- 8.0
- See Also:
 
- 
XOFF
- 
DC4public static final byte DC4Device Control 4. Characters for the control of ancillary devices associated with data processing or telecommunication systems, more especially switching devices "on" or "off." (If a single "stop" control is required to interrupt or turn off ancillary devices, DC4 is the preferred assignment.)- Since:
- 8.0
- See Also:
 
- 
NAKpublic static final byte NAKNegative Acknowledge: A communication control character transmitted by a receiver as a negative response to the sender.- Since:
- 8.0
- See Also:
 
- 
SYNpublic static final byte SYNSynchronous Idle: A communication control character used by a synchronous transmission system in the absence of any other character to provide a signal from which synchronism may be achieved or retained.- Since:
- 8.0
- See Also:
 
- 
ETBpublic static final byte ETBEnd of Transmission Block: A communication control character used to indicate the end of a block of data for communication purposes. ETB is used for blocking data where the block structure is not necessarily related to the processing format.- Since:
- 8.0
- See Also:
 
- 
CANpublic static final byte CANCancel: A control character used to indicate that the data with which it is sent is in error or is to be disregarded.- Since:
- 8.0
- See Also:
 
- 
EMpublic static final byte EMEnd of Medium: A control character associated with the sent data which may be used to identify the physical end of the medium, or the end of the used, or wanted, portion of information recorded on a medium. (The position of this character does not necessarily correspond to the physical end of the medium.)- Since:
- 8.0
- See Also:
 
- 
SUBpublic static final byte SUBSubstitute: A character that may be substituted for a character which is determined to be invalid or in error.- Since:
- 8.0
- See Also:
 
- 
ESCpublic static final byte ESCEscape: A control character intended to provide code extension (supplementary characters) in general information interchange. The Escape character itself is a prefix affecting the interpretation of a limited number of contiguously following characters.- Since:
- 8.0
- See Also:
 
- 
FSpublic static final byte FSFile Separator: These four information separators may be used within data in optional fashion, except that their hierarchical relationship shall be: FS is the most inclusive, then GS, then RS, and US is least inclusive. (The content and length of a File, Group, Record, or Unit are not specified.)- Since:
- 8.0
- See Also:
 
- 
GSpublic static final byte GSGroup Separator: These four information separators may be used within data in optional fashion, except that their hierarchical relationship shall be: FS is the most inclusive, then GS, then RS, and US is least inclusive. (The content and length of a File, Group, Record, or Unit are not specified.)- Since:
- 8.0
- See Also:
 
- 
RSpublic static final byte RSRecord Separator: These four information separators may be used within data in optional fashion, except that their hierarchical relationship shall be: FS is the most inclusive, then GS, then RS, and US is least inclusive. (The content and length of a File, Group, Record, or Unit are not specified.)- Since:
- 8.0
- See Also:
 
- 
USpublic static final byte USUnit Separator: These four information separators may be used within data in optional fashion, except that their hierarchical relationship shall be: FS is the most inclusive, then GS, then RS, and US is least inclusive. (The content and length of a File, Group, Record, or Unit are not specified.)- Since:
- 8.0
- See Also:
 
- 
SPpublic static final byte SPSpace: A normally non-printing graphic character used to separate words. It is also a format effector which controls the movement of the printing position, one printing position forward. (Applicable also to display devices.)- Since:
- 8.0
- See Also:
 
- 
SPACE
- 
DELpublic static final byte DELDelete: This character is used primarily to "erase" or "obliterate" erroneous or unwanted characters in perforated tape.- Since:
- 8.0
- See Also:
 
- 
MINpublic static final char MINThe minimum value of an ASCII character.- Since:
- 9.0 (was type intbefore 12.0)
- See Also:
 
- 
MAXpublic static final char MAXThe maximum value of an ASCII character.- Since:
- 9.0 (was type intbefore 12.0)
- See Also:
 
 
- 
- 
Method Details- 
toLowerCaseReturns a copy of the input string in which all uppercase ASCII characters have been converted to lowercase. All other characters are copied without modification.
- 
toLowerCaseReturns a copy of the input character sequence in which all uppercase ASCII characters have been converted to lowercase. All other characters are copied without modification.- Since:
- 14.0
 
- 
toLowerCasepublic static char toLowerCase(char c) If the argument is an uppercase ASCII character, returns the lowercase equivalent. Otherwise returns the argument.
- 
toUpperCaseReturns a copy of the input string in which all lowercase ASCII characters have been converted to uppercase. All other characters are copied without modification.
- 
toUpperCaseReturns a copy of the input character sequence in which all lowercase ASCII characters have been converted to uppercase. All other characters are copied without modification.- Since:
- 14.0
 
- 
toUpperCasepublic static char toUpperCase(char c) If the argument is a lowercase ASCII character, returns the uppercase equivalent. Otherwise returns the argument.
- 
isLowerCasepublic static boolean isLowerCase(char c) Indicates whethercis one of the twenty-six lowercase ASCII alphabetic characters between'a'and'z'inclusive. All others (including non-ASCII characters) returnfalse.
- 
isUpperCasepublic static boolean isUpperCase(char c) Indicates whethercis one of the twenty-six uppercase ASCII alphabetic characters between'A'and'Z'inclusive. All others (including non-ASCII characters) returnfalse.
- 
truncateTruncates the given character sequence to the given maximum length. If the length of the sequence is greater thanmaxLength, the returned string will be exactlymaxLengthchars in length and will end with the giventruncationIndicator. Otherwise, the sequence will be returned as a string with no changes to the content.Examples: Ascii.truncate("foobar", 7, "..."); // returns "foobar" Ascii.truncate("foobar", 5, "..."); // returns "fo..."Note: This method may work with certain non-ASCII text but is not safe for use with arbitrary Unicode text. It is mostly intended for use with text that is known to be safe for use with it (such as all-ASCII text) and for simple debugging text. When using this method, consider the following: - it may split surrogate pairs
- it may split characters and combining characters
- it does not consider word boundaries
- if truncating for display to users, there are other considerations that must be taken into account
- the appropriate truncation indicator may be locale-dependent
- it is safe to use non-ASCII characters in the truncation indicator
 - Throws:
- IllegalArgumentException- if- maxLengthis less than the length of- truncationIndicator
- Since:
- 16.0
 
- 
equalsIgnoreCaseIndicates whether the contents of the given character sequencess1ands2are equal, ignoring the case of any ASCII alphabetic characters between'a'and'z'or'A'and'Z'inclusive.This method is significantly faster than String.equalsIgnoreCase(String)and should be used in preference if at least one of the parameters is known to contain only ASCII characters.Note however that this method does not always behave identically to expressions such as: - string.toUpperCase().equals("UPPER CASE ASCII")
- string.toLowerCase().equals("lower case ascii")
 due to case-folding of some non-ASCII characters (which does not occur in String.equalsIgnoreCase(String)). However in almost all cases that ASCII strings are used, the author probably wanted the behavior provided by this method rather than the subtle and sometimes surprising behavior oftoUpperCase()andtoLowerCase().- Since:
- 16.0
 
 
-