Java面向对象_常用类库api
StringBuffer
例:
1 public class StringBufferDemo { 2 3 /** 4 * @param args 5 */ 6 public static void main(String[] args) { 7 // TODO Auto-generated method stub 8 //使用String的写法连接字符串,比较占内存 9 String s="hello"; 10 String ss=s+"world"; 11 for(int i=0;i<10;i++){ 12 s+="hello"+i; 13 } 14 System.out.println(s); 15 //StringBuffer 16 StringBuffer sb=new StringBuffer(100);//带容量 17 for(int i=0;i<10;i++){ 18 sb.append(i); 19 } 20 System.out.println(sb); 21 } 22 23 }
程序国际化Locale类
Locale(String language)
Locale(String language,String country)
通过静态方法创建Locale:
getDefault()
1 public class LocaleDemo { 2 3 /** 4 * @param args 5 */ 6 public static void main(String[] args) { 7 // TODO Auto-generated method stub 8 Scanner input=new Scanner(System.in); 9 Locale locale=Locale.CHINA; 10 locale.getCountry(); 11 12 Locale locale2=new Locale("en","US"); 13 14 ResourceBundle rb=ResourceBundle.getBundle("com.vince.info",locale); 15 System.out.println(rb.getString("welcome")); 16 System.out.println(rb.getString("input.username")); 17 String username=input.next(); 18 System.out.println(rb.getString("input.psw")); 19 String password=input.next(); 20 if("abc".equals(username)&&"123".equals(password)){ 21 22 String info=MessageFormat.format(rb.getString("info"),"abc");//处理动态文本 23 System.out.println(info); 24 } 25 } 26 27 }
实现国际化,要File->new->File