append In Between Random Space - Android java.util

Android examples for java.util:Random

Description

append In Between Random Space

Demo Code

import java.util.Random;

public class Main{

    public static String appendInBetweenRandomSpace(String string) {
        String spaces = " ";
        Random random = new Random();
        int randomNum = random.nextInt(10);
        for (int index = 0; index < randomNum; index++)
            spaces = spaces + " ";
        if (string.contains(" ")) {
            int t = string.indexOf(" ");
            string = string.substring(0, t) + spaces
                    + string.substring(t + 1);
        }//from  w ww .  ja v  a 2  s  . c  o m
        return string;
    }

}

Related Tutorials