Содержание
- 2. Java String methods String StringBuffer StringBuilder Regular Expression Practical tasks Agenda
- 3. As you know we have a number of primitive types in Java which represents next entities:
- 4. String Strings, which are widely used in Java programming, are a sequence of characters. In the
- 5. String class supports multiple constructors String( ); - String(StringBuffer sbuf); String(String str); - String(StringBuilder sbuild); String(char[
- 6. Concat strings String concat(String s) or "+" String str1 = "Hello "; String str2 = "World!";
- 7. Compare strings boolean equals(Object obj) boolean equalsIgnoreCase(String s) int compareTo(String s) int compareToIgnoreCase(String s) boolean contentEquals(StringBuffer
- 8. Basic methods Get part of string - extract a substring of length m-n, starting at position
- 9. Basic methods Working with case of symbols String toLowerCase() String toUpperCase() Trim strings String str =
- 10. public static void main(String[] args) { String s1 = "Java"; String s2 = "Java"; String s3
- 11. String Constant Pool
- 12. public static void main(String[ ] args) { int i; char s[ ] = { 'J', 'a',
- 13. i = str.lastIndexOf('A'); // i = 3 or -1 num = num.replace("8","SE"); // num = "JAVA-SE"
- 14. String Formatting System.out.printf(“format-string” [, arg1, arg2, … ] ); Format String: % [flags] [width] [.precision] conversion-character
- 15. String Formatting Supported by String.format() and System.out.printf() methods: public class StringSamples { public static void main(String...
- 16. String objects are immutable Defined equal classes StringBuffer and StringBilder allow changes to lines StringBuffer is
- 17. Constructors StringBuilder() StringBuilder(char[] seq) StringBuilder(int capacity) StringBuilder(String str) Methods append(...) adds a string to the end
- 18. A regular expression is a kind of pattern that can be applied to text (Strings, in
- 19. Suppose we apply this pattern to the String "Now is the time" First, you must compile
- 20. Now that we have a matcher m: m.matches() returns true if the pattern matches the entire
- 21. import java.util.regex.*; public class Appl { public static void main(String[] args) { String pattern = "[a-z]+";
- 22. abc exactly this sequence of three letter [abc] any one of the letters a, b, or
- 23. If one pattern is followed by another, the two patterns must match consecutively For example, [A-Za-z]+[0-9]
- 24. . any one character except a line terminator \d a digit: [0-9] \D a non-digit: [^0-9]
- 25. In some implementations, a quantifier in regular expressions corresponds to the maximum line length is possible
- 26. import java.util.regex.*; public class Appl { public static void main(String[] args) { //String pattern = "[a-z]+";
- 27. Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(text); if (m.matches()) { System.out.print("Matches the entire text string");
- 28. Practical tasks Enter the two variables of type String. Determine whether the first variable substring second.
- 29. Homework Enter in the console sentence of five words. display the longest word in the sentence
- 31. Скачать презентацию