A method that returns a hash code for a character.
The hash code is calculated by the following formula,
s [k] is the kth character of the index, and when the string is String.length () = 0, String.hashCode will be 0 ~~ (I don't care because java will do it for me. You don't have to do it) ~~.
A method that returns the maximum value of the specified string, that is, the index number where the specified string appears last. The argument can also be specified in Unicode. You can also specify an index number to start the search and start from there.
Returns true if the specified string is in the search string as a prefix.
StarrtsWithSample.java
public class StarrtsWithSample {
public static void main(String[] args) {
String str = "Java String";
System.out.println(str.startsWith("Java")); //Java~
System.out.println(str.startsWith(" Strin")); //Strin~
System.out.println(str.startsWith("Java Str")); //Java Str~
System.out.println(str.startsWith("ing")); //ing~
System.out.println(str.startsWith("J")); //J~
}
}
The execution result is
true
false
true
false
true
If there is a character string with the specified prefix, it will return true. In the above example, Java ~, Strin ~, Java Str ~, ing ~, and J ~ are searched as prefixes.
Contrary to the previous startsWith, this time it specifies a suffix and returns true if the string is in the search string.
For example, if you write something that searches for English words to see if there is ~ ing behind it,
EndsWithSample.java
public class EndsWithSample {
public static void main(String[] args) {
String[] strs = {"trying","boolean","string","building","having","catch","throw"};
for(String str : strs){
System.out.println("Search string: " + str);
if(str.endsWith("ing")){
System.out.println("There is ~ ing.");
} else {
System.out.println("There is no ~ ing.");
}
}
}
}
The result is as follows.
Search string: trying
There is ~ ing.
Search string: boolean
There is no ~ ing.
Search string: string
There is ~ ing.
Search string: building
There is ~ ing.
Search string: having
There is ~ ing.
Search string: catch
There is no ~ ing.
Search string: throw
There is no ~ ing.
A method that returns true when length () = 0.
A method that splits by a specified string and returns the result as an array. It is also possible to specify how many times to divide.
The following is the one that divides the URL with /
SplitSample.java
public class SplitSample {
public static void main(String[] args) {
String str = "developers.google.com/analytics/devguides/reporting/mcf/v3/";
for(String part : str.split("/")) {
System.out.println(part);
}
}
}
Result is
developers.google.com
analytics
devguides
reporting
mcf
v3
become.
A method that returns a character string (String type) as an array of Char.
For example
ToCharArraySample.java
public class ToCharArraySample {
public static void main(String[] args) {
String str = "Google";
char[] char1 = str.toCharArray();
for(char partChar : char1) {
System.out.println(partChar);
}
}
}
When you execute
G
o
o
g
l
e
Is returned and stored in a char type array.