������
������Java ������������������������������������������������������������������������������ ���������String ������������������������������������������������������������������������������������������������
- repeat(int count)���������������������������������������������������������������������������������������������
- isBlank()������������������������������������������������������������ 0 ���������������������������������������
- lines()������������������������������������������������������������
- strip()������������������������������������������������������������������������������������������������������������
- stripLeading()���������������������������������������������������������������������������������������������
- stripTrailing()���������������������������������������������������������������������������������������������
- formatted(Object... args)���������������������������������������������������������������������������������
- translateEscapes()������ Java ������������������������������������������������������������������������
- transform() ���������������������������������������������������������������������
������
1. repeat(int count)
public class StringRepeatExample {
public static void main(String[] args) {
String str = "abc";
String repeatedStr = str.repeat(3);
System.out.println(repeatedStr);
}
}
������������
���������������
abcabcabc
������������
2. isBlank()
public class StringIsBlankExample {
public static void main(String[] args) {
String str1 = "";
String str2 = " ";
String str3 = " \t ";
System.out.println(str1.isBlank());
System.out.println(str2.isBlank());
System.out.println(str3.isBlank());
}
}
������������
���������������
true
true
true
������������
3. lines()
import java.util.stream.Stream;
public class StringLinesExample {
public static void main(String[] args) {
String str = "Hello\nWorld\nJava";
Stream<String> lines = str.lines();
lines.forEach(System.out::println);
}
}
������������
���������������
Hello
World
Java
������������
4. strip()
public class StringStripExample {
public static void main(String[] args) {
String str1 = " abc ";
String str2 = "\t def \n";
System.out.println(str1.strip());
System.out.println(str2.strip());
}
}
������������
���������������
abc
def
������������
5. stripLeading()
public class StringStripLeadingExample {
public static void main(String[] args) {
String str1 = " abc ";
String str2 = "\t def \n";
System.out.println(str1.stripLeading());
System.out.println(str2.stripLeading());
}
}
������������
���������������
abc
def
������������
6. stripTrailing()
public class StringStripTrailingExample {
public static void main(String[] args) {
String str1 = " abc ";
String str2 = "\t def \n";
System.out.println(str1.stripTrailing());
System.out.println(str2.stripTrailing());
}
}
������������
���������������
abc
def
������������
7. formatted(Object... args)
public class StringFormattedExample {
public static void main(String[] args) {
String str = "My name is %s, I'm %d years old.";
String formattedStr = str.formatted( "John", 25);
System.out.println(formattedStr);
}
}
������������
���������������
My name is John, I'm 25 years old. ������������
8. translateEscapes()
public class StringTranslateEscapesExample {
public static void main(String[] args) {
String str = "Hello\\nWorld\\tJava";
String translatedStr = str.translateEscapes();
System.out.println(translatedStr);
}
}
������������
���������������
Hello
World Java
������������
9. transform()
public class StringTransformExample {
public static void main(String[] args) {
String str = "hello world";
byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
String newStr = new String(bytes, StandardCharsets.ISO_8859_1);
System.out.println(newStr);
}
}
������������
���������������
hello world
������������
��������������������������������������������� "hello world" ��� UTF-8 ��������������� ISO-8859-1 ���������������������������������������������������������������������������������������������������������������������������������������������������������������������
������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������




