当我将其传递给构造函数时:{12,1,3,22,0,4}
public class Test
{
private ArrayList<int[]> arraylistone;
public Test(int[] ab) //todo
{
int[] xy = new int[2];
arraylistone = new ArrayList<int[]>(ab.length);
for(int i=0; i < ab.length; i++){
int sv = String.valueOf(ab[i]).length();
if (sv == 1){
xy[0] = 0;
xy[1] = ab[i];
arraylistone.add(xy);
}
else if(sv == 2){
//TODO
}
else{
System.out.println("errormessage");
//throw argument "too many digits..."
}
System.out.println(arraylistone); // want to check that the array list ab has been added converterted into two single digit numbers (xy) and stored in arraylistone
}
}
}
arraylistone
?我想打印出它的值,以确保我在正确的轨道上,如果我以某种方式使用toString()
将数组对象转换为String
?现在,它打印出类似这样的东西`&#34; [I @ 72d67791] [I @ 72d67791] [I @ 72d67791]&#34; &#34;`
(sv == 2)
我如何获得int
中每个人int
的{{1}}值?例如,给定String
12,如果我将其划分为单独的int
xy = int[]
和xy[0] =1
答案 0 :(得分:-1)
我认为这会让你大吃一惊。老师肯定会喜欢这个:D:
public Test(@NotNull int[] ab) //todo
{
List<int[]> arraylistone = new ArrayList<int[]>(ab.length) {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
for (int[] ints : this) {
sb.append(Arrays.toString(ints));
}
return sb.toString();
}
};
System.out.println("how many strings "+ab.length); //testing
for (int i = 0; i < ab.length; ++i) {
int sv = String.valueOf(ab[i]).length();
int[] xy = new int[sv];
for (int t, base = 10, s = 0; s < xy.length; ++s) {
here:{
t = ab[i] / (int) Math.pow(base, --sv);
if (t / base == 0) break here;
t %= t / base * base;
} xy[s] = t;
}
arraylistone.add(xy);
}
System.out.println(arraylistone); // want to check that the array list ab has been added to arraylistone
}