字符串常用方法
首字符变大写
package com.li.changGe.commonlyusedClass.strings;
import java.util.Locale;
public class StringMethodDemo01 {
public static void main(String[] args) {
String name = "Hello World java ";
char a = name.charAt(4);
boolean contains = name.contains("java");
char[] chars = name.toCharArray();
int index = name.indexOf("o",5);
index = name.lastIndexOf("l");
name = name.trim();
name = name.toLowerCase(Locale.ROOT);
name = name.toUpperCase(Locale.ROOT);
contains = name.endsWith("JAVA");
contains = name.startsWith("HELLO");
name = name.replace("JAVA","testJava");
String[] arrays = name.split("[ ,]+");
arrays[0] = name.substring(1,8);
contains = name.equalsIgnoreCase("hello world testjava");
index = "aba".compareTo("abb");
name = new StringMethodDemo01().firstToUpperCase("this is a apple");
System.out.println(name);
}
public String firstToUpperCase(String name){
String[] arrays = name.split(" ");
name = name.replace(name.toString(),"");
for (String array : arrays) {
String substring = array.substring(0, 1);
substring = substring.toUpperCase(Locale.ROOT);
array = substring + array.substring(1,array.length()) + " ";
name += array;
}
name = name.trim();
return name;
}
}