Java – how to automatically split large strings in IntelliJ ideas?

I'm testing with a long string So I need to split such a large string:

privat static final String TOO_LONG_JSON = "{field1:field1,field2:field2 ... fieldN:fieldN}";

Will become:

private static final String TOO_LONG_JSON = "{field1:field1,field2:field2" + 
    "{field3:field3,field4:field4,field6:field6,field7:field7}" +
    "{field8:field8,field9:field9,field10:field10,field11:field11}" +
    " ... fieldN:fieldN}";

Can I set up IntelliJ ideas to automatically split large strings?

Solution

You can use automatic formatting (Ctrl Alt L) with few changes in code style settings

>Press Ctrl Alt s to open the settings window > find code style / Java section > make sure the line break option is unchecked and the make sure the right margin is not exceeded option > press OK to accept your changes

Now, when using auto format (Ctrl Alt L), long strings that exceed the line character limit will be automatically cut into multiple lines

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>