字符串toCharArray - 性能优化

1. 良好的风格:

 
String s = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
  char[] ch = s.toCharArray();
  int len = ch.length;
  for(int i = 0; i < len; i++) {
	if (ch[i] == '*') {
	    // .....
	}
  }

2. 不好的风格:
  
String s = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
   for (int i = 0; i < s.length(); i++) {
        if (s.charAt(i) == '*') {
            //......
        }
   } 

你可能感兴趣的:(java,编程)