簡體   English   中英

LibGDX And​​roid Stringbuilder最有效的方法?

[英]LibGDX Android Stringbuilder most efficient Way?

祝大家有個美好的一天,我有一個小問題,什么是經常將很多不同的字符串添加到另一個String的最佳方法,尤其是在LibGDX中?

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

我必須在盡可能短的時間內執行此方法幾百次。 有誰知道,在Android的LibGdx中最有效的方法是什么?

在此先感謝您的答案

編輯

整個循環:

                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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM