我是java和hbase的初学者,我想缩短代码,所以在代码中使用for循环。如果输入字符串stumber为“aaaa0000?0”,则结果应为“aaaa000000”、“aaaa000010”、“aaaa000020”、“aaaa000030”…“aaaaaa000090”
此源代码运行良好:
List<Get> gets = new ArrayList<>();
for (String stumber : stumbersArr) {
if(stumber.charAt(8) == '?'){
get = new Get((stumber.replace(stumber.charAt(8), '0')).getBytes());
get.setMaxVersions(versions);
gets.add(get);
get = new Get((stumber.replace(stumber.charAt(8), '1')).getBytes());
get.setMaxVersions(versions);
gets.add(get);
get = new Get((stumber.replace(stumber.charAt(8), '2')).getBytes());
get.setMaxVersions(versions);
gets.add(get);
get = new Get((stumber.replace(stumber.charAt(8), '3')).getBytes());
get.setMaxVersions(versions);
gets.add(get);
get = new Get((stumber.replace(stumber.charAt(8), '4')).getBytes());
get.setMaxVersions(versions);
gets.add(get);
get = new Get((stumber.replace(stumber.charAt(8), '5')).getBytes());
get.setMaxVersions(versions);
gets.add(get);
get = new Get((stumber.replace(stumber.charAt(8), '6')).getBytes());
get.setMaxVersions(versions);
gets.add(get);
get = new Get((stumber.replace(stumber.charAt(8), '7')).getBytes());
get.setMaxVersions(versions);
gets.add(get);
get = new Get((stumber.replace(stumber.charAt(8), '8')).getBytes());
get.setMaxVersions(versions);
gets.add(get);
get = new Get((stumber.replace(stumber.charAt(8), '9')).getBytes());
get.setMaxVersions(versions);
gets.add(get);
}else{
get = new Get(stumber.trim().getBytes());
get.setMaxVersions(versions);
gets.add(get);
}
}
Result[] results = table.get(gets);
但是在我用for循环修改之后,代码没有给出结果。为什么?
List<Get> gets = new ArrayList<>();
for (String stumber : stumbersArr) {
if(stumber.charAt(8) == '?'){
for (int i =0; i<10; i++){
get = new Get((stumber.replace(stumber.charAt(8), 'i')).getBytes());
get.setMaxVersions(versions);
gets.add(get);
}
}else{
get = new Get(stumber.trim().getBytes());
get.setMaxVersions(versions);
gets.add(get);
}
}
Result[] results = table.get(gets);
2条答案
按热度按时间31moq8wy1#
for循环的内部应该是:
什么给了你
i
价值观char
.roqulrg32#
可以使用character.fordigit()将int i转换为char,如下所示: