如何在Java中连接两个字符串? [英] How do I concatenate two strings in Java?

查看:167
本文介绍了如何在Java中连接两个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Java中连接字符串。为什么这不起作用?

I am trying to concatenate strings in Java. Why isn't this working?

public class StackOverflowTest {  
    public static void main(String args[]) {
        int theNumber = 42;
        System.out.println("Your number is " . theNumber . "!");
    }
}


推荐答案

你可以使用 + 运算符连接字符串:

You can concatenate Strings using the + operator:

System.out.println("Your number is " + theNumber + "!");

theNumber 隐式转换为String 42

theNumber is implicitly converted to the String "42".

这篇关于如何在Java中连接两个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆