Java Stream Operation mkString(Stream items, String prefix, String delimiter, String suffix)

Here you can find the source of mkString(Stream items, String prefix, String delimiter, String suffix)

Description

mk String

License

Apache License

Declaration

public static String mkString(Stream<String> items, String prefix, String delimiter, String suffix) 

Method Source Code


//package com.java2s;
/* /*from  w  ww. j a  v a  2s .  co  m*/
 * Copyright 2016 BananaRama.
 *
 * 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.StringJoiner;
import java.util.stream.Stream;

public class Main {
    public static String mkString(Stream<String> items, String prefix, String delimiter, String suffix) {
        StringJoiner joiner = new StringJoiner(delimiter);
        items.forEach(joiner::add);
        return prefix + joiner.toString() + suffix;
    }
}

Related

  1. makeStream(final Object[] array)
  2. mapElementsSizes(IntStream intStream)
  3. maximum(final Stream stream)
  4. maxLong(Stream stream)
  5. maxStringLength(Stream stringStream)
  6. nullableStreamOf(Collection nullableCollection)
  7. ofType(Stream stream, Class type)
  8. opt2stream(Optional opt)
  9. optionalToStream(final Optional optional)