Repeat a string @param s the string @param n the amount of times to repeat @return the repeated string
(String s, int n)
| 1337 | * @return the repeated string |
| 1338 | */ |
| 1339 | public static String repeat(String s, int n) { |
| 1340 | if (s == null) { |
| 1341 | return null; |
| 1342 | } |
| 1343 | |
| 1344 | final StringBuilder sb = new StringBuilder(); |
| 1345 | |
| 1346 | for (int i = 0; i < n; i++) { |
| 1347 | sb.append(s); |
| 1348 | } |
| 1349 | |
| 1350 | return sb.toString(); |
| 1351 | } |
| 1352 | } |