Содержание
- 2. AGENDA String Regular expression
- 3. STRING Java String methods String StringBuffer StringBuilder
- 4. Class String As you know we have a number of primitive types in Java which represents
- 5. String Strings, which are widely used in Java programming, are a sequence of characters. In the
- 6. String String class supports multiple constructors String( ); - String(StringBuffer sbuf); String(String str); String(StringBuilder sbuild); String(char[
- 7. Basic methods Concat strings String concat(String s) or "+" String str1 = "Hello "; String str2
- 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. Basic methods Compare strings boolean equals(Object obj) boolean equalsIgnoreCase(String s) int compareTo(String s) int compareToIgnoreCase(String s)
- 11. Example public static void main(String[ ] args) { int i; char s[ ] = { 'J',
- 12. Example i = str.lastIndexOf('A'); // i = 3 or -1 num = num.replace("8","SE"); // num =
- 13. Java String methods public class Appl2 { public static void main(String[] args) { String s1 =
- 14. String Constant Pool
- 15. String Formatting System.out.printf(“format-string” [, arg1, arg2, … ] ); Format String: % [flags] [width] [.precision] conversion-character
- 16. String Formatting Supported by String.format() and System.out.printf() methods: public class StringSamples { public static void main(String...
- 17. StringBuilder and StringBuffer String objects are immutable Defined equal classes StringBuffer and StringBilder allow changes to
- 18. StringBuilder Constructors StringBuilder() StringBuilder(char[] seq) StringBuilder(int capacity) StringBuilder(String str) Methods append(...) – adds a string to
- 19. Text blocks A text block is a multi-line string literal that avoids the need for most
- 20. REGULAR EXPRESSION
- 21. “Some people, when confronted with a problem, think, ‘I know, I’ll use regular expressions.’ Now they
- 22. Regular Expression A regular expression is a kind of pattern that can be applied to text
- 23. Regular Expression Suppose we apply this pattern to the String "Now is the time" First, you
- 24. Regular Expression Now that we have a matcher m: m.matches() returns true if the pattern matches
- 25. Regular Expression import java.util.regex.*; public class Appl1 { public static void main(String[] args) { String pattern
- 26. Regular Expression abc exactly this sequence of three letter [abc] any one of the letters a,
- 27. Regular Expression If one pattern is followed by another, the two patterns must match consecutively For
- 28. Regular Expression . any one character except a line terminator \d a digit: [0-9] \D a
- 29. Regular Expression In some implementations, a quantifier in regular expressions corresponds to the maximum line length
- 30. Regular Expression public class Appl { public static void main(String[] args) { //String pattern = "[a-z]+";
- 31. Regular Expression Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(text); if (m.matches()) { System.out.print("Matches the entire
- 32. Capturing group In regular expressions, parentheses are used for grouping, but they also capture (keep for
- 33. Double backslashes Backslashes have a special meaning in regular expressions; for example, \b means a word
- 34. Escaping metacharacters A lot of special characters--parentheses, brackets, braces, stars, plus signs, etc.--are used in defining
- 35. Spaces There is only one thing to be said about spaces (blanks) in regular expressions, but
- 36. Regular expressions are a language Regular expressions are not easy to use at first It’s a
- 37. Practical tasks Enter the two variables of type String. Determine whether the first variable substring second.
- 38. Homework Enter in the console sentence of five words. display the longest word in the sentence
- 40. Скачать презентацию