This is the first post. This time, I summarized the character operations. It's basic, so I'll look back when I forget it.
public class Main{
public static void main(String[] args){
String s1 = "Studying Java";
String s2 = "Java";
String s3 = "java";
String s4 = "Javascript";
String s5 = "javascript";
String s6 = "";
String s7 = "Study Java";
String s8 = " j a v a ";
String s9 = " j a v a ";
String s10 = "jjjjjjjjjj";
String s11 = "jjjjjaaaaavvvvvaaaaa";
String s12 = "j";
String s13 = "0123456789";
String s14 = "a0b1c2d3e4f5g6h7i8j9k10";
String s15 = "0a1b2c3d4e5f6g7h8i9j10k";
String s16 = "a,0,b,1,c,2,d,3,e,4,f,5,g,6,h,7,i,8,j,9,k,10";
//Check if the character contents are equal
//The character you want to search.equals(The character you want to search)
if(s2.equals(s3)){
System.out.println("s2 and s3 are the same character");
}else{
System.out.println("s2 and s3 are not equal");
}
//Check if the characters are equal without case sensitivity The character you want to search for.equalsIgnoreCase(The character you want to search)
if(s2.equalsIgnoreCase(s3)){
System.out.println("s2 and s3 are the same character");
}else{
System.out.println("s2 and s3 are not equal");
}
//Display the length of the character string The character you want to search for.lenght()
System.out.println(s4.length());
//Check if it is an empty character The character you want to search.isEmpty()
if(s6.isEmpty()){
System.out.println("s6 is an empty string");
}else{
System.out.println("s6 is not an empty string");
}
//Find out if the string s is included The character you want to search for.contains(The character you want to search)
if(s4.contains(s2)){
System.out.println("s2 is included in s4");
}else{
System.out.println("s4 does not include s2");
}
//Find out if it starts with the string s The character you want to search for.startsWith(The character you want to search)
if(s4.startsWith(s2)){
System.out.println("s4 starts with Java");
}else{
System.out.println("s4 doesn't start with Java");
}
//Find out if it ends with the string s The character you want to search for.endsWith(The character you want to search)
if(s4.endsWith(s2)){
System.out.println("s4 ends with Java");
}else{
System.out.println("s4 does not end with Java");
}
//Find the place where the character string s first appears from the beginning. The character you want to search.indexof(Search character)
System.out.println(s2.indexOf(s4)); //-If 1, the search character does not exist
System.out.println(s4.indexOf(s2)); //0 or more is the position where the search character occurs
//Find the place where the string s first appears from behind. The character you want to search.lastIndexOf(Search character)
System.out.println(s2.lastIndexOf(s4)); //-If 1, the search character does not exist
System.out.println(s7.lastIndexOf(s2)); //0 or more is the position where the search character occurs
//Cut out only one character at the specified position The character you want to search.charAt(Location of the character you want to cut out)
System.out.println(s7.charAt(1)); //Strong is displayed
//Cut out characters of arbitrary length from the specified position Characters you want to search.substring(Location of the character you want to cut out)
System.out.println(s7.substring(1)); //Strong Java displays
System.out.println(s7.substring(1,4)); //Strong Ja is displayed
//Convert uppercase to lowercase Characters you want to convert.toLowerCase()
System.out.println(s2.toLowerCase()); //Java becomes java
//Convert lowercase letters to uppercase characters.toUpperCase()
System.out.println(s2.toUpperCase()); //java becomes JAVA
//Eliminate whitespace before and after characters Characters you want to convert.trim()
System.out.println(s8.trim()); //j a v a becomes JAVA
//Replace string Characters you want to convert.replace(Characters you want to convert,Converted characters)
System.out.println(s9.replace("j","a")); //Displayed as a a v a
System.out.println(s9.replace(" ","")); //Remove whitespace in java and display characters
StringBuilder hoge = new StringBuilder(); //New StringBuilder instance to hoge
for(int i = 0; i < 1000; i++) { //Repeat for internal processing 1000 times
hoge.append("a"); //Add a to hoge
hoge.append("z"); //Add z to hoge
}
//Character pattern check(Regular expressions)The character you want to search.matches(Characters to compare)
//Do the characters in the variable match the characters in Java?
System.out.println(s7.matches("Study Java")); //true
System.out.println(s7.matches("study")); //false
System.out.println(s7.matches("Java")); //false
Recommended Posts