How do I concatenate two strings in Java?

前端 未结 23 3416
长情又很酷
长情又很酷 2020-11-22 04:47

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

public class StackOverflowTest {  
    public static void main(String args[]) {
                


        
23条回答
  •  深忆病人
    2020-11-22 05:13

    The concatenation operator in java is +, not .

    Read this (including all subsections) before you start. Try to stop thinking the php way ;)

    To broaden your view on using strings in Java - the + operator for strings is actually transformed (by the compiler) into something similar to:

    new StringBuilder().append("firstString").append("secondString").toString()
    

提交回复
热议问题