Ad
Code
Diff
  • package space;
    public class SpaceMaker
    {
      public static String spaceMakerV1(String str)
      {
        return str.replaceAll(".(?=.)", "$0 ");
      }
    }
    • package space;
    • import static java.util.stream.Collectors.joining;
    • public class SpaceMaker{
    • public static String spaceMakerV1(String str){
    • return str.chars()
    • .mapToObj(c -> String.valueOf((char)c))
    • .collect(joining(" "));
    • }
    • public static String spaceMakerV2(String str){
    • char[] chars = str.toCharArray();
    • StringBuilder spaced = new StringBuilder();
    • for(char c:chars){
    • spaced.append(c).append(' ');
    • }
    • return spaced.toString().trim();
    • public class SpaceMaker
    • {
    • public static String spaceMakerV1(String str)
    • {
    • return str.replaceAll(".(?=.)", "$0 ");
    • }
    • }