Java why charsequence




















All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy. This interface provides uniform, read-only access to many different kinds of char sequences. Refer to Unicode Character Representation for details. Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a CharSequence. Removes a part of a CharSequence by replacing the first occurrence of target within self with empty string and returns the result.

Removes a part of a CharSequence. This replaces the first occurrence of the pattern within self with empty string and returns the result. It increments the last character in the given CharSequence. If the last character in the CharSequence is Character. The empty CharSequence is incremented to a string consisting of the character Character. Pads a CharSequence to a minimum length specified by numberOfChars by adding the space character to the left as many times as needed.

An example: println 'Numbers:' [1, 10, , ]. Pads a CharSequence to a minimum length specified by numberOfChars , adding the supplied padding CharSequence as many times as needed to the left.

If the CharSequence is already the same size or bigger than the target numberOfChars , then the toString of the original CharSequence is returned. Pads a CharSequence to a minimum length specified by numberOfChars by adding the space character to the right as many times as needed.

Pads a CharSequence to a minimum length specified by numberOfChars , adding the supplied padding CharSequence as many times as needed to the right.

Overloads the -- operator for the class CharSequence. It decrements the last character in the given CharSequence. The empty CharSequence can't be decremented. Replaces all occurrences of replacement CharSequences supplied via a map within a provided CharSequence with control over the internally created StringBuilder's capacity.

This method uses a StringBuilder internally. Java auto-expands a StringBuilder's capacity if needed. In rare circumstances, the overhead involved with repeatedly expanding the StringBuilder may become significant.

If you have measured the performance of your application and found this to be a significant bottleneck, use this variant to have complete control over the internally created StringBuilder's capacity.

Replaces all occurrences of replacement CharSequences supplied via a map within a provided CharSequence. Replaces all occurrences of a captured group by the result of calling a closure on that text. Examples: assert "hello world". Replaces each substring of this CharSequence that matches the given regular expression with the given replacement. Replaces all occurrences of a captured group by the result of a closure call on that text.

For examples, assert "hello world". Replaces all substrings of a CharSequence that match the given compiled regular expression with the given replacement. Use Matcher quoteReplacement to suppress the special meaning of these characters, if desired. Replaces the first occurrence of a captured group by the result of a closure call on that text. For example with some replaceAll variants thrown in for comparison purposes , assert "hello world". Replaces the first substring of this CharSequence that matches the given regular expression with the given replacement.

Replaces the first substring of a CharSequence that matches the given compiled regular expression with the given replacement.

Splits a CharSequence with whitespace as delimiter. Similar to tokenize, but returns an Array of String instead of a List. Iterates through the given CharSequence line by line, splitting each line using the given regex delimiter. The list of tokens for each line is then passed to the given closure. Iterates through the given CharSequence line by line, splitting each line using the given separator Pattern.

Checks whether this CharSequence starts with the searchString ignoring the case considerations. Strips leading spaces from every line in a CharSequence. The line with the least number of leading spaces determines the number to remove. Lines only containing whitespace are ignored when calculating the number of leading spaces to strip. Strips numChars leading characters from every line in a CharSequence.

Returns the first num elements from this CharSequence. Returns the CharSequence that exists after the first occurrence of the given searchString in this CharSequence. Groovy team" assert text. Groovy team' assert text. Returns the CharSequence that exists before the first occurrence of the given searchString in this CharSequence. Takes the characters between the first occurrence of the two subsequent enclosure strings. Takes the characters between nth specified by occurrence pair of enclosure strings.

Returns the CharSequence that is in between the first occurrence of the given from and to CharSequences and empty if the unavailable inputs are given. Returns the CharSequence that is in between the given the nth specified by occurrence pair of from and to CharSequences and empty if the unavailable inputs are given. Returns the last num elements from this CharSequence.

VisruthCV Updated the link, now it points to the Java 7 version. Sajith Janaprasad Sajith Janaprasad 1 1 gold badge 11 11 silver badges 22 22 bronze badges. I disagree with your closing sentence. One of the methods on CharSequence is toString , so anything that can be done with a String can be done with an arbitrary CharSequence too just call toString on it and use whatever manipulation ability you were thinking of. AndrzejDoyle: toString might be really expensive for a particular implementation though.

Most implementations need to copy the entire sequence of characters into a new array. If your first step is to obtain a String from the CharSequence , you're providing flexibility at the cost of hiding the performance hit. There's not much value in that, and might as well take a String and let the user do the conversion so they're well aware of the penalty.

AndrzejDoyle: Mark Peters has answered for me and I like to add one thing to it. You are suggesting to use CharSequence.

Then you don't have to convert your CharSequence to a String. I think there is plenty to learn from the String API if just because of regular expressions. Final note: only two of those methods of CharSequence may give you advantages over String : subSequence and charAt. If a parameter is conceptually a sequence of chars, use CharSequence.

Community Bot 1 1 1 silver badge. SpaceTrucker SpaceTrucker 12k 6 6 gold badges 53 53 silver badges 95 95 bronze badges.

Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Does ES6 make JavaScript frameworks obsolete? Podcast Do polyglots have an edge when it comes to mastering programming Any other code units, including ordinary BMP characters, unpaired surrogates, and undefined code units, are zero-extended to int values which are then passed to the stream.

Returns: an IntStream of Unicode code points from this sequence Since: 1. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. All rights reserved.

Use is subject to license terms. Also see the documentation redistribution policy. Skip navigation links. This interface provides uniform, read-only access to many different kinds of char sequences.



0コメント

  • 1000 / 1000