Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java中操作字符串都有哪些类?它们之间有什么区别? #233

Open
zhonghuasheng opened this issue Apr 1, 2020 · 0 comments
Labels

Comments

@zhonghuasheng
Copy link
Owner

主要有三种:String, StringBuffer, StringBuilder
String是不可变的对象,每次对String类型的改变都可能会生成一个新的对象
StringBuffer和StringBuilder是可以改变的对象。
对于操作效率:StringBuilder > StringBuffer > String
对于线程安全:StringBuffer是线程安全的,可用于多线程(关键方法基本都使用synchronized关键字修饰);StringBuilder是非线程安全的,用于单线程
不频繁的字符串操作使用String

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant