Sting 字符串操作

===============代码==================

package com.cratd;


import java.util.Random;


public class mymain {


/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

int a;

int[] b = new int[5];

int[] x = new int[3];

int[] [] y= new int[3] [5];

for(int i=0;i<3;i++){

for(int j=0;j<5;j++){

y[i][j]=j+i;

}

}

for(int i=0;i<3;i++){

for(int j=0;j<5;j++){

System.out.print(y[i][j]+" ");

}

System.out.print("\n");

}

System.out.print("\n");

System.out.print("\n");

System.out.print("\n");

for(int i=0;i<5;i++){

for(int j=0;j<3;j++){

System.out.print(y[j][i]+" ");

}

System.out.print("\n");

}

int p=0;

char ch='b';

String s1="celloword";

String s2="word";

//equalsIgnoreCase

System.out.print(s1.equalsIgnoreCase(s2));

System.out.print("\n");

//compareTo

System.out.print(s1.compareTo(s2));

System.out.print("\n");

//startWith

System.out.print(s1.startsWith(s2));

System.out.print("\n");

//endWith

System.out.print(s1.endsWith(s2));

System.out.print("\n");

//indexOf

System.out.print(s1.indexOf("w"));

System.out.print("\n");

//charAt

System.out.print(s1.charAt(5));

System.out.print("\n");

//substring

System.out.print(s1.substring(5));

System.out.print("\n");

System.out.print(s1.substring(3,6));

System.out.print("\n");

//concat

System.out.print(s1.concat(s1));

System.out.print("\n");

//replace 

System.out.print(s1.replace("word", "?"));

System.out.print("\n");

//trim

String s3="    word   ";

System.out.print("^"+s3+"^");

System.out.print("\n");

System.out.print(s3.trim());

System.out.print("\n");

//toUpperCase toLowerCase

String s4= "CrATd";

System.out.print(s4.toUpperCase());

System.out.print("\n");

System.out.print(s4.toLowerCase());

System.out.print("\n");

}


}

==============输出===================

0 1 2 3 4 

1 2 3 4 5 

2 3 4 5 6 




0 1 2 

1 2 3 

2 3 4 

3 4 5 

4 5 6 

false

-20

false

true

5

w

word

low

cellowordcelloword

cello?

^    word   ^

word

CRATD

cratd


你可能感兴趣的:(字符串,常见,几个)