Java String Repeat repeat(String s, int times)

Here you can find the source of repeat(String s, int times)

Description

repeat

License

Open Source License

Declaration

public static String repeat(String s, int times) 

Method Source Code

//package com.java2s;
/*//  www.j  a  v a2 s.co m
 * Swift Parallel Scripting Language (http://swift-lang.org)
 * Code from Java CoG Kit Project (see notice below) with modifications.
 *
 * Copyright 2005-2014 University of Chicago
 *
 * 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.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class Main {
    public static String repeat(String s, int times) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < times; i++) {
            sb.append(s);
        }
        return sb.toString();
    }

    /**
       Like Java Map.toString() but no curly braces
     */
    public static String toString(Map<String, ? extends Object> map) {

        if (map == null)
            return "null";

        StringBuilder sb = new StringBuilder(map.size() * 128);
        Set<String> keys = map.keySet();
        Iterator<String> it = keys.iterator();
        while (it.hasNext()) {
            String key = it.next();
            Object value = map.get(key);
            sb.append(key);
            sb.append('=');
            sb.append(value);
            if (it.hasNext())
                sb.append(',');
        }
        return sb.toString();
    }

    public static String toString(List<? extends Object> l) {
        if (l == null) {
            return "null";
        }
        return l.toString();
    }
}

Related

  1. repeat(String item, int count)
  2. repeat(String pattern, int count)
  3. repeat(String s, int cnt)
  4. repeat(String s, int times)
  5. repeat(String s, int times)
  6. repeat(String str, int count)
  7. repeat(String str, int repeat)
  8. repeat(String str, int repeat)
  9. repeat(String string, int n)