fill array with filling char - Java Collection Framework

Java examples for Collection Framework:Array Fill

Description

fill array with filling char

Demo Code


//package com.java2s;

import java.util.Arrays;

public class Main {
    public static void main(String[] argv) throws Exception {
        int fillingLength = 2;
        char fillingChar = 'a';
        System.out.println(filler(fillingLength, fillingChar));
    }//from w  w  w  .  ja  v  a 2s .c  o m

    public static String filler(int fillingLength, char fillingChar) {
        char[] buf = new char[fillingLength];

        Arrays.fill(buf, 0, buf.length, fillingChar);

        String res = new String(buf);

        return res;
    }
}

Related Tutorials