zoukankan      html  css  js  c++  java
  • Java 中数字和字符串拼接的问题

    注意细节

    字符是char 类型,字符串是String 类型
    1、数字拼接char,得到的还是数字,相当于和它的ASCII编码相加(如果定义成String 会编译错误)
    2、数字拼接String,得到的是String
    3、数字同时拼接char 和 String,就看和谁先拼接,和谁后拼接
    4、String 拼接任何类型,得到的都是String

    public static void main(String[] args) {
        String s1 = 1234 + '_' + "test";
        System.out.println("s1 = " + s1);
        String s2 = 1234 + "_" + "test";
        System.out.println("s2 = " + s2);
        String s3 = "test" + '_' + 1234;
        System.out.println("s3 = " + s3);
        String s4 = "test" + 1234 + 56789;
        System.out.println("s4 = " + s4);
        System.out.println('_');
        System.out.println(0 + '_');
    }

     得到的结果是:

    s1 = 1329test
    s2 = 1234_test
    s3 = test_1234
    s4 = test123456789
    _
    95

  • 相关阅读:
    自动构建部署
    EF 性能调优
    断点续传
    gis 相关资料
    easyui 特殊操作
    KJ面试
    前端面试题汇总
    es6之扩展运算符 三个点(...)
    vue.js开发环境搭建
    gulp 环境搭建
  • 原文地址:https://www.cnblogs.com/acm-bingzi/p/java_char_string.html
Copyright © 2011-2022 走看看