编程知识 cdmana.com

50 examples of reading Java efficient code

Reference resources

  • Declare methods that are not related to class member variables as static methods
  • If the initial value of the variable is overwritten , There's no need to give variables an initial value

image.png
image.png

  • Try to use shift instead Positive integer Multiplication and division
  • Use "+" For string conversion , Easy to use but inefficient , It is recommended to use String.valueOf

image.png

  • Do not use size Method detect empty , You have to use isEmpty Method detect empty . whatever isEmpty The time complexity of method implementation is 0(1), But some size The time complexity of method implementation may be 0(n)

版权声明
本文为[Virtuous fish]所创,转载请带上原文链接,感谢

Scroll to Top