• String 对象是不可修改的,对于被String 重载的'+' 和'+=' 运算符来说,当你用它们来连接两个String 对象的时候,它在底层并不会对于每一次连接均生成一个String 对象,取而代之,在底层会有一个非线程安全的可修改的StringBuilder 对象被构造出来,并且调用其append()方法来生成我们需要拼接的字符串。关于这一点,我们可以随便编写一个字符串拼接语句,然后使用JDK自带的javap 工具,通过javap -c 编译后的类文件名 命令来查看其对应的JVM字节码(相当于汇编语言)来得到一些启示。不过,应当注意的一点是,在循环语句块中拼接字符串,在每次循环的过程中都会生成一个新的StringBuilder 对象(即该对象的构造发生在循环的内部),因此,如果你关注程序的性能,那么这种情况下显式地使用StringBuilder 对象的append 方法是很有必要的。不过,像append(a + ":" + c) 这种语句,对于内部的连接语句,编译器又会帮你生成一个新的StringBuilder 对象,这种情况下可以分步append:append(a).append(":").append(c)。
  • StringBuilder was introduced in Java SE5. Prior to this, Java used StringBuffer, which ensured thread safety and so was significantly more expensive. Thus, string operations in Java SE5/6 should be faster.
  • 如果重写了某个类的toString 方法,那么不要在其中单纯地使用this 拼接字符串,因为这会导致程序无限递归调用该类的toString 方法,最终导致栈溢出。如果想要获取该对象的地址,可以调用super.toString() 或者Integer.toHexString(this.hashCode()) 来获得。
  • Formatter provides powerful control over spacing and alignment with fairly concise notation.

Regular expressions

  • In general, you'll compile regular expression objects rather than using the fairly limited String utilities. To do this, you import java.util.regex, then compile a regular expression by using the static Pattern.compile() method. This produces Pattern object based on its String argument. You use the Pattern by calling the matcher() method, passing the string that you want to search. The matcher() method produces a Matcher object, which has a set of operations to choose from(you can see all of these in the JDK documentation for java.util.regex.Matcher). For example, the replaceAll() method replaces all the matches with its argument.
  • find() is like an iterator, moving forward through the input string.
  • Groups are regular expressions set off by parentheses that can be called up later with their group number. Group 0 indicates the whole expression match, group 1 is the first parenthesized group, etc. Thus in A(B(C))D, There are three groups: Group 0 is ABCD, group 1 is BC, and group 2 is C.

最新文章

  1. [APUE]UNIX进程的环境(下)
  2. SILVERLIGHT 应急卫生模拟演练项目之GRID布局
  3. MySQL配置文件改变了datadir值
  4. 精品素材:WALK & RIDE 单页网站模板下载
  5. 虚拟机 vlan trunk 特性
  6. K - Work 分类: 比赛 2015-07-29 19:13 3人阅读 评论(0) 收藏
  7. ASP.NET MVC4 学习系统四(视图)
  8. PageView
  9. CSS display:inline和float:left两者区别探讨
  10. Kattis - Biased Standings
  11. [转]8 Regular Expressions You Should Know
  12. spark-shell报错:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/fs/FSDataInputStream
  13. .net DLL版本管理
  14. 获取高精度时间注意事项 (QueryPerformanceCounter , QueryPerformanceFrequency)
  15. 基于w2v词向量聚类出现的问题(有待解决)
  16. tomcat nginx默许的post大小限制
  17. 怎么修改wamp的本地时间
  18. Erlang:Error in process ... with exit value
  19. springboot-18-springboot的参数封装
  20. django中django.conf.urls.url函数

热门文章

  1. 2019-7-29-Roslyn-使用-Target-替换占位符方式生成-nuget-打包
  2. JDBC 操作数据库实例
  3. 【arc077f】AtCoder Regular Contest 074 F - Lotus Leaves
  4. Flask中的session机制
  5. 中介者模式(Mediator、ConcreteMediator、Colleague Class)(租房中介)
  6. System V启动脚本启动的服务
  7. js实现翻转一个字符串
  8. web前端学习(三)css学习笔记部分(2)-- css定位+盒子操作
  9. Vim 中自定义注释快捷键
  10. Leetcode905.Sort Array By Parity按奇偶排序数组