Java中的String运算符 [英] + operator for String in Java

查看:109
本文介绍了Java中的String运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几分钟前看过这个问题,并决定看看java字符串用于检查 + 运算符是否存在重载的类。

I saw this question a few minutes ago, and decided to take a look in the java String class to check if there was some overloading for the + operator.

我找不到任何内容,但我知道我能做到这一点

I couldn't find anything, but I know I can do this

String ab = "ab";
String cd = "cd";
String both = ab + cd; //both = "abcd"

实施的地方在哪里?

推荐答案

来自精细手册


Java语言为字符串连接运算符(+)提供特殊支持,并且将其他对象转换为字符串。字符串连接是通过 StringBuilder (或 StringBuffer )类及其追加方法。字符串转换是通过方法toString实现的,由Object定义并由Java中的所有类继承。有关字符串连接和转换的其他信息,请参阅Gosling,Joy和Steele, Java语言规范

The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings. String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method. String conversions are implemented through the method toString, defined by Object and inherited by all classes in Java. For additional information on string concatenation and conversion, see Gosling, Joy, and Steele, The Java Language Specification.

请参阅 String Concatenation JLS。

这篇关于Java中的String运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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