日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

String练习代码保存

發(fā)布時間:2024/8/23 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 String练习代码保存 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
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(".");//獲取“.”坐標(biāo)String subString = s.substring(index);//截取字符串System.out.println(subString);}System.out.println("----------類型轉(zhuǎn)換-----------------");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
———-類型轉(zhuǎn)換—————–
123
———–字符串中空格問題—————-
非空
7
5

package com.test;import java.io.Console; import java.util.Arrays; import java.util.Scanner;public class Main {;public static void main(String[] agrs){char[] cs = new char[]{'A', 'b', 'c'};String str1 = new String(cs);System.out.println("-------------變成哈希值--------------");System.out.println(str1.getBytes());System.out.println("---------------輸出ASCII碼值------------");System.out.println(Arrays.toString(str1.getBytes()));System.out.println("-------------length--------------");System.out.println("AAA".length());System.out.println("------------索引獲取值---------------");System.out.println("AAAc".charAt(3));System.out.println("-----------------返回指定的子字符串出現(xiàn)位置----------");String values1 = "abcdeafbc";String subStr = "fbc";System.out.println(values1.indexOf(subStr));//第一次出現(xiàn)的位置System.out.println(values1.lastIndexOf(subStr));//返回最后一次出現(xiàn)的索引System.out.println("-------------equals--------------");String s1 = new String("abc");String s2 = new String("abc");System.out.println(s1==s2);System.out.println(s1.equals(s2));System.out.println("-------------valueOf--------------");int num = 123;String t = "234";System.out.println(t.valueOf(true));System.out.println(t);System.out.println("-------------大小寫轉(zhuǎn)換--------------");System.out.println(s1.toUpperCase());System.out.println(str1.toLowerCase());System.out.println("------------end---------------");} }

答案:
————-變成哈希值————–
[B@1bbf1ca
—————輸出ASCII碼值————
[65, 98, 99]
————-length————–
3
————索引獲取值—————
c
—————–返回指定的子字符串出現(xiàn)位置———-
6
6
————-equals————–
false
true
————-valueOf————–
true
234
————-大小寫轉(zhuǎn)換————–
ABC
abc
————end—————

總結(jié)

以上是生活随笔為你收集整理的String练习代码保存的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。