java: use StringBuilder to insert at the beginning

前端 未结 9 2134
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-30 03:55

I could only do this with String, for example:

String str=\"\";
for(int i=0;i<100;i++){
    str=i+str;
}

Is there a way to achieve this wit

9条回答
  •  不知归路
    2021-01-30 04:07

    Maybe I'm missing something but you want to wind up with a String that looks like this, "999897969594...543210", correct?

    StringBuilder sb = new StringBuilder();
    for(int i=99;i>=0;i--){
        sb.append(String.valueOf(i));
    }
    

提交回复
热议问题