网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.Struts应用程序的流程控制简介.
.Java Servlet 编程及应用之六.
.使用Soap消息调用Web Servi.
.Java编程测试1M内存可用来缓存多.
.API解读:Thread.
.bug? Hbm2JavaTask无法实现joine.
.Java环境 使用Resin在NT环境下配.
.使用BufferedReader读取文件.
.JavaServer Pages Second Edition.
.实战体会Java多线程编程精要之基.
.Effective java学习笔记6:避免使.
.谈模式(SingletonPattern)的变形.
.用 for/in 在 Java 5.0 中增强循.
.Java抽取Word,PDF格式文件的四种.
.邂逅StringIndexOutOfBoundsExce.
.Java程序开发中代理技术的使用方.
.Java编程经验技巧 谨慎使用Date和.
.Kodo EJB:符合EJB3规范的持久层.
.关于java socket的问题.
.Java设计模式之Observer.

Java String 的 equals() 方法可能的优化

发表日期:2008-1-5



JDK1.4, 1.5 的 String Class 代码如下











[code]











public final class String











    implements Java.io.Serializable, Comparable<String>, CharSequence











{











    /** The value is used for character storage. */











    private final char value[];












 


 



 



    /** The offset is the first index of the storage that is used. */











    private final int offset;












 


 



 



    /** The count is the number of characters in the String. */











    private final int count;











[/code]












 


 



 



[code]











    /**











     * Initializes a newly created <code>String</code> object so that it











     * represents the same sequence of characters as the argument; in other











     * Words, the newly created string is a copy of the argument string. Unless











     * an eXPlicit copy of <code>original</code> is needed, use of this











     * constrUCtor is unnecessary since Strings are immutable.











     *











     * @param   original   a <code>String</code>.











     */











    public String(String original) {











            int size = original.count;











            char[] originalValue = original.value;











            char[] v;











            if (originalValue.length > size) {











                // The array representing the String is bigger than the new











                // String itself.  Perhaps this constructor is being called











                // in order to trim the baggage, so make a copy of the array.











                v = new char[size];











                System.arraycopy(originalValue, original.offset, v, 0, size);











            } else {











                // The array representing the String is the same











                // size as the String, so no point in making a copy.











                v = originalValue;











            }











            this.offset = 0;











            this.count = size;











            this.value = v;











    }











[/code]











从这段构造函数中,我们可以看出,不同Reference的String之间有可能共享相同的 char[]。
上一篇:Java 编程技术中汉字问题的分析及解决(1) 人气:466
下一篇:JAVA 的MD5加密算法源代码 人气:2889
浏览全部Java的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐