Java Stream Operation replacePos(StringBuilder original, char replacementChar, Stream positionsToReplace)

Here you can find the source of replacePos(StringBuilder original, char replacementChar, Stream positionsToReplace)

Description

Replaces each position in the original string with the replacement character.

License

Apache License

Parameter

Parameter Description
original the string to perform a replacement on
replacementChar the character used to replace each position
positionsToReplace the 0-based position(s) (index) in the original string to replace

Exception

Parameter Description
IndexOutOfBoundsException if the position is not between 0 and original.length()

Return

the original StringBuilder instance, which may have had replacement operations performed on it

Declaration

static StringBuilder replacePos(StringBuilder original, char replacementChar, Stream<Integer> positionsToReplace) 

Method Source Code

    //package com.java2s;
    /*/*from   ww w  .  j a va2 s.  c om*/
     * Copyright 2017 Johns Hopkins University
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *     http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */

    import java.util.stream.Stream;

    public class Main {
        /**
         * Replaces each position in the original string with the replacement character.
         *
         * @param original the string to perform a replacement on
         * @param replacementChar the character used to replace each position
         * @param positionsToReplace the 0-based position(s) (index) in the original string to replace
         * @return the {@code original} StringBuilder instance, which may have had replacement operations performed on it
         * @throws IndexOutOfBoundsException if the position is not between 0 and original.length()
         */
        static StringBuilder replacePos(StringBuilder original, char replacementChar, Stream<Integer> positionsToReplace) {
    positionsToReplace.forEach((index) -> original.setCharAt(index, replacementChar));
    return original;
}
    }

Related

  1. parallelStreamFromIterable(Iterable in)
  2. prepend(final T first, final Stream rest)
  3. rangeStream(int n, boolean parallel)
  4. readStream(Stream s, boolean lowercase)
  5. rebuildParallel(Stream stream)
  6. replaceStr(StringBuilder original, char replacementChar, Stream stringsToReplace)
  7. reverse(Stream stream)
  8. reverse(Stream input)
  9. startsWith(Stream stream, Iterable iterable)