zoukankan      html  css  js  c++  java
  • StringDemo3

    package cn.zuoye;
    /*
     * string的转换功能
     * byte[] getBytes();把字符串转换为字节数组
     * char[] toCharArray();把字符串转换为字符数组
     * static string valueOf(char[] chs);把字符数组转换为字符串
     * static string valueOf(int i);把int类型的数组转换成字符串
     *      string类的valueOf方法可以把任意类型的数据转换成字符串
     * string toLowerCase();把字符串转换成小写
     * string toUpperCase();把字符串转换成大写
     * string concat(string str);把字符串拼接
     */
    public class StringDemo3 {
     public static void main(String[] args) {
      // 定义一个字符串对象
      String s = "helloWorld";
      int s1 = 1234;
      // byte[] getBytes();把字符串转换为字节数组
      byte[] b = s.getBytes();
      for (int i = 0; i < b.length; i++) {
       System.out.println(b[i]);
      }
      // char[] toCharArray();把字符串转换为字符数组
      char[] c = s.toCharArray();
      for (int i = 0; i < c.length; i++) {
       System.out.println(c[i]);
      }
      // static string valueOf(char[] chs);把字符数组转换为字符串
      System.out.println(String.valueOf(s));
      // static string valueOf(int i);把int类型的数组转换成字符串
      System.out.println(String.valueOf(s1));
      
      //string toLowerCase();把字符串转换成小写
      System.out.println(s.toLowerCase());
      
      //string toUpperCase();把字符串转换成大写
      System.out.println(s.toUpperCase());
      
      // string concat(string str);把字符串拼接
      System.out.println(s.concat(s));
     }
    }
  • 相关阅读:
    20172302 201720182 《程序设计与数据结构》实验二报告
    20172302 201720182 《程序设计与数据结构》实验一报告
    20172302 《程序设计与数据结构》第五周学习总结
    POJ 1061 青蛙的约会
    hdu 2485 Highways
    UVA 10608
    hdu 1213 how many tables
    java类static成员加载顺寻
    C# virtual,override或者new
    vs无法在WEB服务器上启动调试
  • 原文地址:https://www.cnblogs.com/rong123/p/9894456.html
Copyright © 2011-2022 走看看