Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

javaÖÐStringÓëStringBufferµÄÇø±ð

ÔÚjavaÖÐÓÐ3¸öÀàÀ´¸ºÔð×Ö·ûµÄ²Ù×÷¡£
 
1.Character ÊǽøÐе¥¸ö×Ö·û²Ù×÷µÄ£¬
 
2.String ¶ÔÒ»´®×Ö·û½øÐвÙ×÷¡£²»¿É±äÀà¡£
 
3.StringBuffer Ò²ÊǶÔÒ»´®×Ö·û½øÐвÙ×÷£¬µ«ÊǿɱäÀà¡£
 
String:
ÊǶÔÏó²»ÊÇԭʼÀàÐÍ.
Ϊ²»¿É±ä¶ÔÏó,Ò»µ©±»´´½¨,¾Í²»ÄÜÐÞ¸ÄËüµÄÖµ.
¶ÔÓÚÒѾ­´æÔÚµÄString¶ÔÏóµÄÐ޸Ķ¼ÊÇÖØд´½¨Ò»¸öеĶÔÏó,È»ºó°ÑеÄÖµ±£´æ½øÈ¥.
String ÊÇfinalÀà,¼´²»Äܱ»¼Ì³Ð.
 
StringBuffer:
ÊÇÒ»¸ö¿É±ä¶ÔÏó,µ±¶ÔËû½øÐÐÐ޸ĵÄʱºò²»»áÏñStringÄÇÑùÖØн¨Á¢¶ÔÏó
ËüÖ»ÄÜͨ¹ý¹¹Ô캯ÊýÀ´½¨Á¢,
StringBuffer sb = new StringBuffer();
note:²»ÄÜͨ¹ý¸¶Öµ·ûºÅ¶ÔËû½øÐи¶Öµ.
sb = "welcome to here!";//error
¶ÔÏó±»½¨Á¢ÒÔºó,ÔÚÄÚ´æÖоͻá·ÖÅäÄÚ´æ¿Õ¼ä,²¢³õʼ±£´æÒ»¸önull.ÏòStringBuffer
Öи¶ÖµµÄʱºò¿ÉÒÔͨ¹ýËüµÄappend·½·¨.
sb.append("hello");
 
×Ö·û´®Á¬½Ó²Ù×÷ÖÐStringBufferµÄЧÂÊÒª±ÈString¸ß:
 
String str = new String("welcome to ");
str += "here";
µÄ´¦Àí²½Öèʵ¼ÊÉÏÊÇͨ¹ý½¨Á¢Ò»¸öStringBuffer,Èúîµ÷ÓÃappend(),×îºó
ÔÙ½«StringBuffer toSting();
ÕâÑùµÄ»°StringµÄÁ¬½Ó²Ù×÷¾Í±ÈStringBuffer¶à³öÁËһЩ¸½¼Ó²Ù×÷,µ±È»Ð§ÂÊÉÏÒª´òÕÛ¿Û.
 
²¢ÇÒÓÉÓÚString ¶ÔÏóÊDz»¿É±ä¶ÔÏó,ÿ´Î²Ù×÷Sting ¶¼»áÖØн¨Á¢ÐµĶÔÏóÀ´±£´æеÄÖµ.
ÕâÑùÔ­À´µÄ¶ÔÏó¾ÍûÓÃÁË,¾ÍÒª±»À¬»ø»ØÊÕ.ÕâÒ²ÊÇÒªÓ°ÏìÐÔÄܵÄ.
 
¿´¿´ÒÔÏ´úÂ룺
½«26¸öÓ¢ÎÄ×ÖĸÖظ´¼ÓÁË5000´Î£¬
 
        String tempstr = "abcdefghijklmnopqrstuvwxyz";
        int times = 5000;
        long lstart1 = System.currentTimeMillis();
        String str = "";
        for (int i = 0; i < times; i++) {
            str += tempstr;
        }
        long lend1 = System.currentTimeMillis();
        long time = (lend1 - lstart1);
        System.out.println(time);
¿


Ïà¹ØÎĵµ£º

LinuxÏ°²×°JAVA JDK

1.  ´ÓsunÖ÷Ò³ÏÂÔØJDK for Linux°æ±¾£¬ÎÒµÄÊÇjdk-6u14-linux-i586.bin¡£
2. ¸ÄΪ¿É²Ù×÷Îļþ£¬chmod +x  jdk-6u14-linux-i586.bin
3. °²×° ÔÚµ±Ç°Â·¾¶£¬./jdk-6u14-linux-i586.bin;һ·ȷ¶¨£¬×°ºÃÖ®ºóÔÚͬһĿ¼Ï»áÉú³ÉÒ»¸öÎļþ¼Ð£¬jdk1.6.0_14£¬Àï±ßÊÇһЩlibµÈÎļþ£¬Í¬windowsÏÂÉú³ÉµÄ°²×°Îļþ¼ÐÒ»Ñù¡£
4.Éè ......

java ²é¿´Îļþ¼ÐÏÂÃæËùÓÐÎļþÒÔ¼°Îļþ¼Ð

import java.io.File;
import java.util.Date;
import java.util.Iterator;
import java.util.Vector;
import java.text.SimpleDateFormat;
public class FileViewer {
  File myDir;
  File[] contents;
  Vector vectorList;
  Iterator currentFileView;
  File currentFile;
  ......

Java Swing½Ì³Ì(»ù´¡)


´´½¨Ò»¸öJFrame
ÏÂÃæÓüòµ¥µÄʵÀýÑÝʾÁËJava Swing´´½¨Ò»¸öÄÜÊäÈëÄÚÈݵĴ°¿Ú
public class frameTest(){
  public static void Main(String args[]){
    //´´½¨JFrame¶ÔÏó£¬JFrameÓÃÀ´ÔÚÆÁÄ»ÉÏÏÔʾһ¸öWindows´°¿Ú¡£
    JFrame frame = new JFrame("µÚÒ»¸öJFrame"); &nbs ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ