LibGDX Android Stringbuilder 最有效的方法?

LibGDX Android Stringbuilder most efficient Way?

大家好, 我有一个小问题,经常将许多不同的字符串添加到另一个字符串的最佳方法是什么,尤其是在 LibGDX 中?

blockString=new StringBuilder(blockString).append(String.valueOf(blockCount.length/2+i)).append("][").append(String.valueOf(f)).append("]").append(String.valueOf(t)).toString();

我必须在尽可能短的时间内执行此方法数百次。在 LibGdx on Android 中,有谁知道最有效的方法是什么?

提前感谢您的回答

编辑

整个循环:

                for (int i=-300;i<300;i++){
                    //whole world Generation(taking up nearly no time)
                    int f=0;
                    int max=50;
                    while (f<max){
                        if (blockCount[blockCount.length/2+i][0][0]==32&&blockCount[blockCount.length/2+i][0][1]==0){
                            max=f;
                        }
                        if (!(blockCount[blockCount.length/2+i][f][0]==32&&blockCount[blockCount.length/2+i][f][1]==0)){
                            int t=codeTexture(blockCount[blockCount.length/2+i][f][0],blockCount[blockCount.length/2+i][f][1]);
                            blockString=blockString.concat("["+String.valueOf(blockCount.length/2+i)+"]"+"["+String.valueOf(f)+"]"+String.valueOf(t));

                        }
                        if ((blockCount[blockCount.length/2+i][f][0]==48&&blockCount[blockCount.length/2+i][f][1]==64)||(blockCount[blockCount.length/2+i][f][0]==32&&blockCount[blockCount.length/2+i][f][1]==64)||(blockCount[blockCount.length/2+i][f][0]==0&&blockCount[blockCount.length/2+i][f][1]==64)||(blockCount[blockCount.length/2+i][f][0]==0&&blockCount[blockCount.length/2+i][f][1]==0)||(blockCount[blockCount.length/2+i][f][0]==16&&blockCount[blockCount.length/2+i][f][1]==16)){
                            max=f+10;
                        }
                        f=f+1;
                    }
                 }

您编写的代码将执行与更直接的代码完全相同的代码

blockString += (blockCount.length / 2 + i) + "][" + t;

编辑:要在循环中执行此操作,您的代码应该看起来像

StringBuilder blockStringBuilder = new StringBuilder();
for (int i=-300;i<300;i++){
                //whole world Generation(taking up nearly no time)
                int f=0;
                int max=50;
                while (f<max){
                    if (blockCount[blockCount.length/2+i][0][0]==32&&blockCount[blockCount.length/2+i][0][1]==0){
                        max=f;
                    }
                    if (!(blockCount[blockCount.length/2+i][f][0]==32&&blockCount[blockCount.length/2+i][f][1]==0)){
                        int t=codeTexture(blockCount[blockCount.length/2+i][f][0],blockCount[blockCount.length/2+i][f][1]);
                        blockStringBuilder.append("[").append(blockCount.length/2+i).append("][").append(f).append("]").append(t);

                    }
                    if ((blockCount[blockCount.length/2+i][f][0]==48&&blockCount[blockCount.length/2+i][f][1]==64)||(blockCount[blockCount.length/2+i][f][0]==32&&blockCount[blockCount.length/2+i][f][1]==64)||(blockCount[blockCount.length/2+i][f][0]==0&&blockCount[blockCount.length/2+i][f][1]==64)||(blockCount[blockCount.length/2+i][f][0]==0&&blockCount[blockCount.length/2+i][f][1]==0)||(blockCount[blockCount.length/2+i][f][0]==16&&blockCount[blockCount.length/2+i][f][1]==16)){
                        max=f+10;
                    }
                    f=f+1;
                }
             }
             blockString = blockStringBuilder.toString();