Awe*_*rus 5 java string string-concatenation
我试图更好地理解字符串.我基本上是在制作一个需要大量字符串的程序.但是,很多字符串非常非常相似,只需要在字符串末尾使用不同的单词.
例如
String one = "I went to the store and bought milk"
String two = "I went to the store and bought eggs"
String three = "I went to the store and bought cheese"
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,在处理字符串时最适合采用哪种方法?将2个字符串连接在一起有什么好处而不仅仅是静态字符串,例如性能或内存管理?
例如
String one = "I went to the store and bought "
String two = "milk"
String three = "cheese"
String four = one + two
String five = one + three
Run Code Online (Sandbox Code Playgroud)
我只想弄清楚处理所有这些字符串的最佳方法.(如果它有助于放置我正在使用的一些字符串,我目前有50个,但这个数字可以盈余很多)
小智 2
正如 spooky 所说,代码的主要问题是可读性。除非您正在开发手机程序,否则您不需要管理资源。话虽这么说,无论您是创建大量Strings独立的内容还是将基础内容String与变化的小部分连接起来,这实际上并不重要。无论哪种方式,您都不会真正注意到更好的性能。
| 归档时间: |
|
| 查看次数: |
1682 次 |
| 最近记录: |