Java基础练习 字符串

JAVA基础练习 字符串

1.输出控制台传递的默认参数
public clasa work1(){

public static viod main(String[] args){
System.out.println(args);
}}

2.比较字符串
String str = “xx”;
String str1 = “yy”;

str.compareTo(str1)
str.compareToIgnoreCase(str1)
equals.

3.确定指定的子字符串在字符串内的最后出现位置

strOrig.lastIndexOf(Stringname)

String strOrig = “xyz";
int lastIndex = strOrig.lastIndexOf(x);

4.从字符串删除指定位置的字符
removeCharAt(string,position)

5.用一个字符串替换另一个字符串中的字串
replace()

6.字符串反转
String类型的每次改动是生成一个新的String对象
StringBuffer是对StringBuffer本身进行操作
反转:StringBuffer(string).reverse().toString().

7.在字符串中搜索词组所在的位置

String strOrig = “hello”
int intIndex = strOrig.indexof(“e”);

8.将字符串拆分 split(string)

String str=“this-is-me”;
String[] temp;
temp = str.split(-);

for(int i = 0; i < temp.length(); i++){
System.out.println(temp[i]);
}

9.将字符串全部转换为大写
str.toUpperCase();

10.匹配字符串中的区域
regionMatches();

boolean match = str1.regionMatches(11,str2,12,3)

11.连接两个字符串
“+” append()
StringBuffer result = new StringBuffer();
result.append(yin)

字符串的方法
1.compareTo,compareToIgnoreCase,==,equals
2.lastIndexOf
3.removeCharAt(str,position)
4.replace(a,b)
5.String str = new StringBuffer(string).reverse().toString()
6.int i = str.indexof(e)
7.str = “x-y-z”
String[] temp;
temp = str.split("-");
for(i=0;i<temp.length;i++){
System.out.println(temp[i]);
}
8.str.toUpperCase

9.regionMatches
返回boolean值
boolean match = str1.regionMatches(0,str2,1,5)

  1. StringBuffer result = new StringBuffer();
    result.append(yin);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值