Packing type: Character
1. The isletter() method is used to determine whether the specified character is a letter. If the character is a letter, return true; Otherwise, false is returned.
System.out.println(Character.isLetter('c')); System.out.println(Character.isLetter('6'));
2. The isDigit () method is used to determine whether the specified character is a number. If the character is a number, return true; Otherwise, false is returned.
System.out.println(Character.isDigit('k')); System.out.println(Character.isDigit('6'));
3. The islowercase() method is used to determine whether the specified character is lowercase. Returns true if the character is lowercase; Otherwise, false is returned.
System.out.println(Character.isLowerCase('f')); System.out.println(Character.isLowerCase('F'));
4.isUpperCase() method is used to judge whether the specified character is uppercase. Returns true if the character is uppercase; Otherwise, false is returned.
System.out.println(Character.isUpperCase('v')); System.out.println(Character.isUpperCase('M'));
5. The tolowercase() method is used to convert uppercase characters to lowercase. Returns the lowercase form of converted characters, if any; Otherwise, the character itself is returned.
System.out.println(Character.toLowerCase('b')); System.out.println(Character.toLowerCase('H'));
6.toUpperCase() method is used to convert lowercase characters to uppercase. Returns the uppercase form of converted characters, if any; Otherwise, the character itself is returned.
System.out.println(Character.toUpperCase('h')); System.out.println(Character.toUpperCase('J'));
7.isWhitespace() method is used to judge whether the specified character is a blank character. The blank character includes: space, tab key and line feed character. If the character is a blank character, return true; Otherwise, false is returned.
System.out.println(Character.isWhitespace('c')); System.out.println(Character.isWhitespace(' ')); System.out.println(Character.isWhitespace('\n')); System.out.println(Character.isWhitespace('\t'));
8. The toString () method is used to return a String object representing the specified char value. The result is a String of length 1, consisting only of the specified char. Returns a String representation of the specified char value.
System.out.println(Character.toString('g')); System.out.println(Character.toString('G'));
regular expression
Java is from Java 1 4 began to support regular expressions. Regular expressions are abbreviated as regex, regexp, regxp, etc. Regular expressions define the pattern of strings. Regular expressions can be used to search (find), edit (replace), or process (match) text. Regular expressions are not limited to one language, but there are subtle differences in each language.
Regular expressions contain ordinary characters and metacharacters. Metacharacters are special characters with specific meanings:
^ | Matches the beginning of the input string. |
$ | Matches the position at the end of the input string. |
[abc] | Character set. Matches any character contained. |
[^abc] | Reverse character set. Matches any characters that are not included. |
[a-z] | Character range. Matches any character within the specified range. |
[^a-z] | Reverse range character. Matches any character that is not within the specified range. |
[a-zA-Z0-9] | Any character from a to Z, a to Z, 0 to 9 |
\d | Numeric characters, equivalent to 0-9, |
\w | Matches any word character, including underscores. And "[A-Za-z0-9#]" Equivalent. |
\s | Matches any white space characters, including spaces, tabs, page breaks, and so on. Equivalent to [\ f\n\r\t\v]. |
\D | Non numeric character matching. Equivalent to [^ 0-9]. |
\W | Matches any non word character. And "[^ a-za-z0-u9]" Equivalent. |
\S | Matches any non whitespace characters. Equivalent to [^ \ f\n\r\t\v]. |
? | Matches the preceding character or subexpression zero or once. |
* | Matches the preceding character or subexpression zero or more times. |
+ | Matches the preceding character or subexpression one or more times. |
. | Matches any single character except '\ r\n'. |
| | perhaps |
\ | Marks the next character as a special character, text, back reference, or octal escape character. |
x{n} | n x |
x{n,} | n to multiple x |
x{n,m} | n to m x |
^ | wrong |
() | grouping |
public class RegexTest { public static void main(String[] args) { // String String1="Java123C++456Python789"; //Pattern object set regular expression Pattern p=Pattern.compile("[a-zA-z]+"); //Match object, match string Matcher m=p.matcher(String1); while(m.find()){ System.out.println(m.group()); } } }
public class Regextest1 { public static void main(String[] args) { //Output the contents of the tag in the string String string1="<div>Hello</div>Java<span></span><div>Study</div>"; Pattern p=Pattern.compile("<[a-z]+>(.)</[a-z]+>"); Matcher m=p.matcher(string1); while(m.find()){ // m. Group (group index), the group index starts from 1 System.out.println(m.group(1)); } } }
Object
Object is the parent of all classes, also known as the top parent, also known as the source of all classes. If a class does not specify a parent class, it inherits the object class by default. All classes except object have parent classes. Some methods in object sometimes need to be overridden.
For example, toString() returns the full name @ hash value of the class by default. It is generally used to return the information in the class (or the value of the member variable), so it needs to be rewritten.
Equals() is a method in the Object. By default, it is used to judge the address equality (equivalent to = =), but it is recommended to override equals() to compare the values of equality (for example, the equals() method defined in the String class can compare the values of equality because equals (method) is overridden in the String).
public class ObjectTest extends Object{ private String name; private int age; public ObjectTest() { super(); } public ObjectTest(String name, int age) { super(); this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "ObjectTest [name=" + name + ", age=" + age + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + age; result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ObjectTest other = (ObjectTest) obj; if (age != other.age) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; return true; } public static void main(String[] args) { ObjectTest ob=new ObjectTest(); ObjectTest ob2=new ObjectTest(); System.out.println(ob.toString());//ObjectTest [name=null, age=0] // System.out.println(ob.equals(ob2));//false; The equals method is not overridden System.out.println("fhgj".equals("fhgj"));//true because the equals method is overridden in String System.out.println(ob.equals(ob2));//true, overriding the equals method } }
Math
package d0828; public class MathTest { public static void main(String[] args) { // Maximum System.out.println(Math.max(5.0, 9.0));//9.0 //Maximum System.out.println(Math.min(40, 3.0));//3.0 //rounding System.out.println(Math.round(5.2));//5 //Round up System.out.println(Math.ceil(6.1));//7.0 //Round down System.out.println(Math.floor(5.9));//5.0 //Power seeking System.out.println(Math.pow(2, 3));//8.0 //Open square System.out.println(Math.sqrt(64));//8.0 //Open cube System.out.println(Math.cbrt(27));//3.0 //absolute value System.out.println(Math.abs(-55));//55 //π System.out.println(Math.PI);//3.141592653589793 //random number //[1-100) System.out.println((int)(Math.random()*99+1)); } }