A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© yinping 中级黑马   /  2015-5-17 23:06  /  411 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

public class lianxi {
        public static void main(String[] args) {
       //将字符串转化字符数组
                /*String str = "abcde";
                char[] ch = str.toCharArray();
                System.out.print("[");
                for (int x = 0; x < ch.length; x++) {
                        if (x < ch.length - 1)
                                System.out.print(ch[x] + ",");
                        else
                        System.out.print(ch[x]+"]");*/

                System.out.println("..................");
                //将字符串中的字符替换
                String s=" abcde ";
                String s2=s.replace("cd", "fe");
                System.out.println(s2);
                String s3=s.trim();
                System.out.println(s3);
                }
        }

2 个回复

倒序浏览
恩恩不错额。
回复 使用道具 举报
字符串s替换的时候,s也会跟着变化,这是要注意的。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马