小弟求教问题 如何用java写trim函数的方法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 jdk有现成的trim()可用://这是jdk里面的实现public String trim() { int len = count; int st = 0; int off = offset; /* avoid getfield opcode */ char[] val = value; /* avoid getfield opcode */ while ((st < len) && (val[off + st] <= ' ')) { st++; } while ((st < len) && (val[off + len - 1] <= ' ')) { len--; } return ((st > 0) || (len < count)) ? substring(st, len) : this; } //把jdk里面的实现稍加改造:public static String trim(String src) { if(src == null){ return null; } int count = src.length(); int len = count; int st = 0; char[] val = src.toCharArray(); while ((st < len) && (val[st] <= ' ')) { st++; } while ((st < len) && (val[len - 1] <= ' ')) { len--; } return ((st > 0) || (len < count)) ? src.substring(st, len) : src; } JDK中有src压缩文件的,自己看源代码 //闲的蛋疼,重构一下public static String trim(String src) { if(src == null){ return null; } int start = 0; int end = src.length(); while ((start < end) && (src.charAt(start)<= ' ')) { start++; } while ((start < end) && (src.charAt(end -1)<= ' ')) { end--; } return ((start > 0) || (end < src.length())) ? src.substring(start, end) : src; } 加载数据源的时候不对,求解 java 消息处理组件有哪些? 重谢!!虽然简单,但是我不会的问题~ 如何在实现当鼠标移动到JLabel上面JLabel上面的文字添加一条下划线? 请教字符串替换问题 麻烦解释一下Class类的getDeclaredConstructor(Class[] parameterTypes)方法! 一个菜鸟问题!!!! 求高手指导一个“Java的功能实现与预期不符的Socket代码编程”的技术问题.. java的hook问题。 关于if语句 新手问问题之代码错在哪里 java dom 查找指定节点
public String trim() {
int len = count;
int st = 0;
int off = offset; /* avoid getfield opcode */
char[] val = value; /* avoid getfield opcode */ while ((st < len) && (val[off + st] <= ' ')) {
st++;
}
while ((st < len) && (val[off + len - 1] <= ' ')) {
len--;
}
return ((st > 0) || (len < count)) ? substring(st, len) : this;
}
//把jdk里面的实现稍加改造:
public static String trim(String src) {
if(src == null){
return null;
}
int count = src.length();
int len = count;
int st = 0;
char[] val = src.toCharArray(); while ((st < len) && (val[st] <= ' ')) {
st++;
}
while ((st < len) && (val[len - 1] <= ' ')) {
len--;
}
return ((st > 0) || (len < count)) ? src.substring(st, len) : src;
}
//闲的蛋疼,重构一下
public static String trim(String src) {
if(src == null){
return null;
}
int start = 0;
int end = src.length();
while ((start < end) && (src.charAt(start)<= ' ')) {
start++;
}
while ((start < end) && (src.charAt(end -1)<= ' ')) {
end--;
}
return ((start > 0) || (end < src.length())) ? src.substring(start, end) : src;
}