下载此文档

java字符串.ppt


文档分类: | 页数:约63页 举报非法文档有奖
1/63
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/63 下载此文档
文档列表 文档介绍
第6章字符串
String是类,不是数组,也不是基本数据类型
String定义为final class,使用了copy on write技术
1)String的初始化
String str = new String(“hello”);
String str = “hello”;
2) String对象和String引用
String str1 = new String(“hello”);
String str2 = new String(“hello”);
boolean b = (str1==str2);
boolean b = (str2);
3)new和直接赋值的区别
String str1 = “hello”;
String str2 = “hello”;
boolean b = (str1==str2);
boolean b = (str2);
String VS StringBuffer
当字符串不大会改变的时候使用String,当字符串经常发生变化的时候使用StringBuffer:String 实际上都是常量,字符串的内容永远不会改变;StringBuffer可以为字符预留空间,因此是为经常变化的字符串考虑的
public class Test {    public static void stringReplace (String text) {    text = ('j' , 'i');    }       public static void bufferReplace (StringBuffer text) {    text = ("C");    }        public static void main (String args[]) {     String textString = new String ("java");     StringBuffer textBuffer = new StringBuffer ("java");         stringReplace (textString);     bufferReplace (textBuffer);         (textString + textBuffer);     }     }
public class E6 {  public static void main(String args[]) {   String s1="a";   String s2=new String("a");   String s3="A";   ((s2));   ((s3));   ((s3));  } }
public class E6 {  public static void main(String args[]) {   StringBuffer s1=new StringBuffer("a");   StringBuffer s2=new StringBuffer("a");   ((s2));     } }
public class E6 {  public static void main(String args[]) {   String s1="a";   String s2="a";   String s3=new String("a");   String s4=new String("a");   (s1==s2);   (s3==s4);   (s1==s3);     }   }
public class E6 {  public static void main(String args[]) {   String s1="a";   StringBuffer sb1=new StringBuffer("a");      StringBuffer sb2=sb1;   String s2="a"+"b";   ("b");        (s1==s2);   (sb

java字符串 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数63
  • 收藏数0 收藏
  • 顶次数0
  • 上传人mh900965
  • 文件大小1.04 MB
  • 时间2018-03-22
最近更新