String练习代码保存
生活随笔
收集整理的這篇文章主要介紹了
String练习代码保存
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
package com.test;public class M1001{public static void main(String[] args) {System.out.println("-----------字符串截取----------------");String str = "a,b,c,d,e,,";String[] str1 = null;str1=str.split(",");for(String st : str1){System.out.println(st);}System.out.println("-----------截取文件后綴名 ----------------");String fileNames = "abc.java; hello.text; hello.cpp";String[] lastFileNames = null;lastFileNames = fileNames.split(";");for(String s : lastFileNames){System.out.println(s);int index=s.lastIndexOf(".");//獲取“.”坐標String subString = s.substring(index);//截取字符串System.out.println(subString);}System.out.println("----------類型轉換-----------------");int n = 123;str=str.valueOf(n);System.out.println(str);System.out.println("-----------字符串中空格問題----------------");String _str1 = "";//為空String _str2 = " ";//非空String _str3 = null;//為空String _str = " ";if(_str !=null && !"".equals(_str)){System.out.println("非空");}else{System.out.println("空");}System.out.println(" AB CD ".length());System.out.println(" AB CD ".trim().length());}
}
答案:
———–字符串截取—————-
a
b
c
d
e
———–截取文件后綴名 —————-
abc.java
.java
hello.text
.text
hello.cpp
.cpp
———-類型轉換—————–
123
———–字符串中空格問題—————-
非空
7
5
答案:
————-變成哈希值————–
[B@1bbf1ca
—————輸出ASCII碼值————
[65, 98, 99]
————-length————–
3
————索引獲取值—————
c
—————–返回指定的子字符串出現位置———-
6
6
————-equals————–
false
true
————-valueOf————–
true
234
————-大小寫轉換————–
ABC
abc
————end—————
總結
以上是生活随笔為你收集整理的String练习代码保存的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 递归函数时间复杂度分析
- 下一篇: html之元素与元素的形成