java学习之string类的字符串大小写之间的转换
package com.ifenx8.study.test; import javax.print.DocFlavor.STRING; public class Demo1_Test1 { public static void main(String[] args) { //dome1(); //demo2(); //吧数组中的数据按照指定的格式拼接成一个字符串 //int[] arr = {1 ,2 ,3}; 结果为: "[1, 2, 3]" int [] arr = {1, 2, 3}; String s1 = String.valueOf(arr); String s2 = "["; for (int i = 0; i < arr.length; i++) { if (i ==2){ s2 = s2 + arr[i] + "]"; }else{ s2 = s2 + arr[i] + ", "; } } System.out.print(s2); } public static void demo2() { //要求字符串首字母大写其余的字符都小写 String s1 = "woaIzhOngGuO"; String s2 = s1.substring(0, 1).toUpperCase().concat(s1.substring(1).toLowerCase()); System.out.println(s2); } public static void dome1() { String s1= "aFGFdgdfdgTGRHGSgdfgedgGga"; String s2 = s1.toLowerCase();//把字符串全部转换成小写字母 System.out.println(s2); String s3 = s1.toUpperCase();//把字符串全部转换成大写字母 System.out.println(s3); String s4 = s2.concat(s3);//吧两个字符串拼接起来 System.out.println(s4); } }
评论前必须登录!
注册