码迷,mamicode.com
首页 > 其他好文 > 详细

Sting 字符串操作

时间:2016-05-09 22:19:34      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:字符串几个常见操作方法

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

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


本文出自 “大道至简,天地尽在我心中” 博客,请务必保留此出处http://8392460.blog.51cto.com/8382460/1771574

Sting 字符串操作

标签:字符串几个常见操作方法

原文地址:http://8392460.blog.51cto.com/8382460/1771574

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!