标签:style blog color strong for re c div
以自己在开发引入的BUG为例
public static String splitListByComma(List<String> dogs) { StringBuilder stringBuilder = new StringBuilder(); for (String dogName : dogs) { stringBuilder.append(dogName).append(","); } return stringBuilder.substring(0, stringBuilder.length() - 1); }
BUG:当dogs为空列表时,最后一句会报越界错误(不考虑传入null的情况)。
修正后应该是
public static String splitListByComma(List<String> dogs) { if (dogs.isEmpty()) { return ""; } StringBuilder stringBuilder = new StringBuilder(); for (String dogName : dogs) { stringBuilder.append(dogName).append(","); } return stringBuilder.substring(0, stringBuilder.length() - 1); }
标签:style blog color strong for re c div
原文地址:http://www.cnblogs.com/CanWork/p/3866789.html