String类的常用成员方法

1、  构造方法:

String(byte[] byte,int offset,int length);这个在上面已经用到。

2、  equalsIgnoreCase:忽略大小写的比较,上例中如果您输入的是BYE,则不会退出,因为大小写不同,但是如果使用这个方法,则会退出。

3、  indexOf(int ch);返回字符ch在字符串中首次出现的位置

4、  substring(int benginIndex);

5、  substring(int beginIndex,int endIndex);

返回字符串的子字符串,4返回从benginindex位置开始到结束的子字符串,5返回beginindex和endindex-1之间的子字符串。

基本数据类型包装类的作用是:将基本的数据类型包装成对象。因为有些方法不可以直接处理基本数据类型,只能处理对象,例如vector的add方法,参数就只能是对象。这时就需要使用他们的包装类将他们包装成对象。

 

 1 public class testInteger
 2 {
 3 public static void main(String[] args)
 4 //main()的参数是string类型的数组,用来做为长,宽时,要转换成整型。
 5 {
 6 int w=new Integer(args[0]).intValue();
 7 int h=Integer.parseInt(args[1]);
 8 //int h=Integer.valueOf(args[1]).intValue();
 9 //以上为三种将字符串转换成整形的方法。
10 for(int i=0;i<h;i++)
11 {
12 StringBuffer sb=new StringBuffer(); //使用stringbuffer,是因为它是可追加的。
13 for(int j=0;j<w;j++)
14 {
15 sb.append('*');
16 }
17 System.out.println(sb.toString()); //在打印之前,要将stringbuffer转化为string类型。
18 }
19 }
20 }
原文地址:https://www.cnblogs.com/borter/p/9434080.html