zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    [loj6484]LJJ爱数书
    [loj3163]动态直径
    [loj2983]数树
    [luogu3785]文本校正
    [loj2572]字符串
    [loj3103]节日庆典
    [atARC118F]Growth Rate
    [atARC118E]Avoid Permutations
    [cf794G]Replace All
    [cf756E]Byteland coins
  • 原文地址:https://www.cnblogs.com/shenhainixin/p/5085866.html
Copyright © 2011-2022 走看看