Repeat String in Java
Description
The following code shows how to repeat String.
Example
// w w w.jav a 2 s .co m
public class Main {
public static void main(String[] argv) {
System.out.println(repeatString("java2s.com", 5));
}
public static String repeatString(String what, int times) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < times; i++) {
sb.append(what);
}
return sb.toString();
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »