zoukankan      html  css  js  c++  java
  • java中字符串数组、字符串、整形之间的转换。

    字符串数组转字符串(只能通过for循环):

    String[] str = {'a', 'b', 'd'};

    StringBuffer sb = new StringBuffer();

    for(int i = 0; i < str.length;i++){

      sb.append(str[i]);

    }

    String s = sb.toString();

    字符数组转字符串可以通过下面的方式:

    char[] data =  {'a', 'b', 'd'};

    String s = new String(data);

    字符串到字符数组:

    String str = "123abc";

    char[] ar = str.toCharArray();  //char数组

    for(int i =0;i<ar.length;i++){

      System.out.println(ar[i]);  //1 2 3 a b c
    }
     
    String[] arr = str.split("");
    for(int i =0;i<arr.length;i++){  //String数组,不过arr[0]为空
          System.out.println(arr[i]);  //空  1 2 3 a b c
    }
    整形到字符串:
    String str = Integer.toString(i);
    字符串到整形:
    int i = Integer.valueOf(str).intValue();
     
  • 相关阅读:
    Direct2D Simple
    波动+灰度图+噪点的简单实现
    控制台和窗口应用程序转换
    read from plist file
    1366X768成为全球最流行屏幕分辨率
    游戏框架类
    Animation in Cocos2diphone
    透射
    11.20
    11.19
  • 原文地址:https://www.cnblogs.com/javacatalina/p/6641338.html
Copyright © 2011-2022 走看看