[英]Assign from array to list of strings in Java
Is there a way to get rid of buf
?有没有办法摆脱buf
?
public Option(String opt) {
String[] buf;
buf = opt.split("=");
key = buf[0];
value = buf[1];
}
I thought of something like { key, val } = opt.split("=");
我想到了类似{ key, val } = opt.split("=");
as it would be possible in Perl, IIRC.就像在 Perl、IIRC 中一样。
There is java.util.Scanner
, which gives back one token at a time.有java.util.Scanner
,它一次返回一个令牌。 But it's a lot harder to use than split
, and in my experience not worth the trouble for problems simple enough to handle w/ split
.但是它比split
更难使用,根据我的经验,对于足够简单的问题来处理 w/ split
不值得麻烦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.