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));
     }
    }
  • 相关阅读:
    枚举类型的应用
    动手动脑
    四则运算和验证码--源码
    ATM源码
    javabean+jsp+servlet+jdbc
    四则运算改良
    Java异常
    课后总结
    包装类Integre
    对象验证
  • 原文地址:https://www.cnblogs.com/rong123/p/9894456.html
Copyright © 2011-2022 走看看