字符串代码package com.hanqi;
import java.util.Random;
public class ZFC {
public static void main(String[] args) {
String str1 = "字符串常量";
String str2 = null;
str2 = new String();
str2 = new String("实例化字符串");
char[] c = new char[]{'a','b','c'};
str2 = new String(c);
str2 = ("asdsajkljfadaskllkjflj");
/
/字符集
//str2 = new String(bytes);
System.out.println("str2.length = " + str2.length() );
System.out.println("str2 = " + str2 );
//查字符或字符串
int in = str2.indexOf("bb");
System.out.println("bb = " + in);
int  la = str2.lastIndexOf("d");
System.out.println("d = " + la);
String newStr = str2.substring(5 , 6);
System.out.println("sunstraung() = " + newStr);
str2 = "  abcdad  ";
//去除前后两格
System.out.println("去空格 = " + im()+"后⾯");
//查替换
System.out.println("查替换设备 = " +place(" ", "")+"后⾯");
str2 = "abc,不好";
System.out.println("查替换 = " +placeFirst("abc ", "张三")+"");
str2 = "abcde";
//判断字符串开始和结束
str2.startsWith("a");
System.out.println("判断起始 = " + str2.startsWith("a"));
System.out.println("判断起始" + (str2.indexOf("acb")== 0));
字符串函数源码dsWith("f");
System.out.println("判断结束 = " + dsWith("f"));
str1 = new String("abc");
str2 = new String("abc");
System.out.println("判断字符串相等=" + (str1 == str2));
System.out.println("判断字符串相等=" + (str1.equals(str2)));
str1 = "abc";
str2 = "abc";
System.out.println("判断字符串相等a=" + (str1 == str2));
System.out.println("判断字符串相等b=" + (str1.equals(str2)));    System.out.println("str1 = " + UpperCase());
str2 = "abc#def#ghr#xyz";
String[] array = str2.split("#");
for(int i = 0;i < array.length;i++){
System.out.println("" + array[i]);
}
//数学运算
System.out.println("四舍五⼊="+und(123.456));
//取上限值
System.out.println("取上限值="+il(123.456));
//取下限值
System.out.println("取下限值="+Math.floor(123.456));
System.out.println("PI="+Math.PI);
//随机数
System.out.println("随机数="+Math.random());
Random r= new Random();//时间作为种⼦
//r=new Random(1);//随机数种⼦,出来的结果是不变的
System.out.println("Random随机数="+r.nextInt(1000));
System.out.println("Random随机数="+r.nextInt(1000));
System.out.println("Random随机数="+r.nextInt(100));
System.out.println("Random随机数="+r.nextInt(100));
System.out.println("Random随机数="+r.nextInt(10));
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。