中秋佳节快到了,道长提早在这儿祝大家节日开心!道长也提前准备輸出最终一篇文章,请假。文中详细介绍了Java基本招聘面试中常用的招聘面试专业知识字符串数组。

1.int length(): 回到字符串数组的长短: return value.length2.char charAt(int index): 回到某数据库索引处的标识符return value[index]3.boolean isEmpty(): 分辨是不是空字符串: return value.length == 0String str = " HELLO world ";System.out.println(str.length());//13System.out.println(str.charAt(0));//" "第一个空格符System.out.println(str.charAt(9));//rSystem.out.println(str.isEmpty());//false4.String toLowerCase(): 应用默认设置语言表达自然环境, 将 String 中的全部字符转换为小写字母5.String toUpperCase(): 应用默认设置语言表达自然环境, 将 String 中的全部字符转换为英文大写String str = " HELLO world ";String s1 = str.toLowerCase();//变换全部标识符为---->小写字母String s2 = str.toUpperCase();//变换全部标识符为---->英文大写System.out.println(s1);//" hello world "System.out.println(s2);//" HELLO WORLD "System.out.println(str);//" HELLO world " 不更改原值6.String trim(): 回到字符串数组的团本, 忽视流板空缺和尾端空缺String str = " HELLO world ";String s3 = str.trim();//除去字符串数组头尾空格符System.out.println(s3);//"HELLO world"7.boolean equals(Object obj): 较为字符串数组的信息是不是同样8.boolean equalsIgnoreCase(String anotherString): 与equals方式相近, 忽视英文大小写String s1 = "HELLOWORLD";String s2 = "helloworld";System.out.println(s1.equals(s2));//falseSystem.out.println(s1.equalsIgnoreCase(s2));//true 忽视英文大写小写字母较为9.String concat(String str): 将特定字符串数组联接到此字符串数组的末尾。 等额的于用“ ”String s3 = s1.concat("降龙十八掌");//联接字符串数组,等额的于 “ ”System.out.println(s3);//HELLOWORLD降龙十八掌10.int compareTo(String anotherString): 较为2个字符串数组的大徐熙娣tring s4 = "abc";//97.98.99String s5 = new String("abg");//97.98.103System.out.println(s4.compareTo(s5));//-4 碰到相同绕过,碰到不一样作差,輸出String s6 = "aag";//97.97.103System.out.println(s4.compareTo(s6));//111.String substring(int beginIndex): 回到一个新的字符串数组, 它是此字符串数组的从beginIndex逐渐提取到末尾的一个子字符串数组。12.String substring(int beginIndex, int endIndex) : 回到一个新字符串数组, 它是此字符串数组从beginIndex逐渐提取到endIndex(不包含)的一个子字符串数组。String s7 = "降龙十八掌.六脉神剑.乾坤大挪移";String s8 = s7.substring(6);//切成片实际操作String s9 = s7.substring(6,10);左闭右开[)System.out.println(s8);//六脉神剑.乾坤大挪移System.out.println(s9);//六脉神剑13.boolean endsWith(String suffix): 检测此字符串数组是不是以特定的后缀名完毕14.boolean startsWith(String prefix): 检测此字符串数组是不是以特定的作为前缀逐渐15.boolean startsWith(String prefix, int toffset): 检测此字符串数组从特定数据库索引逐渐的子字符串数组是不是以特定作为前缀逐渐String s1 = "六脉神剑.九阳神功.一阳指";boolean s2 = s1.startsWith("六");//以xx逐渐System.out.println(s2);//trueboolean s3 = s1.startsWith("九阳",5);//从第index处 以xx逐渐System.out.println(s3);//trueboolean s4 = s1.endsWith("指");//以xx完毕System.out.println(s4);//true16.boolean contains(CharSequence s): 当且仅当此字符串包含特定的 char 值编码序列时,回到 trueString s1 = "六脉神剑.九阳神功.一阳指";String s5 = "九阳神功";System.out.println(s1.contains(s5));//true17.int indexOf(String str): 回到特定子字符串数组在这里字符串数组中第一次发生处的数据库索引18.int indexOf(String str, int fromIndex): 回到特定子字符串数组在这里字符串数组中第一次发生处的数据库索引,从特定的数据库索引逐渐19.int lastIndexOf(String str): 回到特定子字符串数组在这里字符串数组中最右侧发生处的数据库索引20.int lastIndexOf(String str, int fromIndex): 回到特定子字符串数组在这里字符串数组中最后一次发生处的数据库索引,从特定的数据库索引逐渐反方向检索注: indexOf和lastIndexOf方式假如找不到全是回到-1String s1 = "六脉神剑.九阳神功.一阳指";System.out.println(s1.indexOf("魔刀"));//2System.out.println(s1.indexOf("魔刀", 6));//-1System.out.println(s1.lastIndexOf("神"));//7System.out.println(s1.lastIndexOf("神", 5));//221.String replace(char oldChar, char newChar): 回到一个新的字符串数组, 它是根据用 newChar 更换此字符串数组中产生的全部 oldChar 获得的。22.String replace(CharSequence target, CharSequence replacement): 应用特定的字颜值更换编码序列更换此字符串数组全部配对字颜值总体目标编码序列的子字符串数组。String s1 = "六脉神剑.九阳神功.一阳指";System.out.println(s1.replace("神", "鬼"));//六脉鬼剑.九阳鬼功.一阳指23.String replaceAll(String regex, String replacement) : 应用给出的replacement 更换此字符串数组全部配对给出的正则表达式的子字符串数组。String str = "12hello34world5java7891mysql456";//把字符串数组中的数据换成 ","假如結果中开头和结尾有,得话除掉String string = str.replaceAll("\\d ", ",").replaceAll("^,|,$", ");//正则表达式System.out.println(string);//hello,world,java,mysql24.String replaceFirst(String regex, String replacement) : 应用给出的replacement 更换此字符串匹配给出的正则表达式的第一个子字符串数组。String s1 = "六脉神剑.九阳神功.一阳指";System.out.println(s1.replace("神", "鬼"));//六脉鬼剑.九阳鬼功.一阳指String str = "1111AAAA2222BBBB999";//把字符串数组中的数据换成,,假如結果中开头和结尾有,得话除掉String string = str.replaceFirst("\\d ", ",");System.out.println(string);//,AAAA2222BBBB99925.boolean matches(String regex): 告之此字符串数组是不是配对给出的正则表达式。String str = "12345";//分辨str字符串数组中是不是所有有数据构成,既有1-n个数据构成boolean matches = str.matches("\\d ");System.out.println(matches);//trueString tel = "0476-4534289";//分辨这是不是一个赤峰市的固话boolean result = tel.matches("0476-\\d{7,8}");System.out.println(result);//true26.String[] split(String regex): 依据给出正则表达式的配对分拆此字符串数组。27.String[] split(String regex, int limit): 依据配对给出的正则表达式来分拆此字符串数组, 较多不超过limit个, 假如超出了, 剩余的列表都放进最后一个原素中。String str = "hello|world|java";String[] strs = str.split("\\|");for (int i = 0; i < strs.length; i ) { System.out.print(strs[i] "\t");}//helloworldjavaSystem.out.println();String str2 = "hello.world.java";String[] strs2 = str2.split("\\.",2);for (int i = 0; i < strs2.length; i ) { System.out.print(strs2[i] "\t");}//helloworld.java

评论(0条)

刀客源码 游客评论