1 개요[ | ]
- Java str_repeat()
Java
Copy
public class MyClass {
public static String str_repeat(String str, int times) {
return new String(new char[times]).replace("\0", str);
}
public static void main(String args[]) {
System.out.println( str_repeat("hello",3) ); // hellohellohello
}
}
Loading
Java
Copy
public class MyClass {
public static String str_repeat(String str, int times) {
StringBuilder sb = new StringBuilder(str.length() * times);
for (int i = 0; i < times; i++) sb.append(str);
return sb.toString();
}
public static void main(String args[]) {
System.out.println( str_repeat("hello",3) ); // hellohellohello
}
}
Loading
2 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.