2012-04-14 15 views
0

私のプロジェクトでは、値を動的に文字列に格納し、その文字列を "、"で分割する必要があります。どうやってやるの ?私を助けて...java androidの文字列に値を動的に格納する方法は?

マイコードしてください:

static ArrayList<ArrayList<String>> listhere; 
ArrayList<String> arropids; 
String arropids1; 


    for(int q=0;q<listhere.size();q++) 
       { 
        arropids = listhere.get(q); 

        if(arropids.get(3).equals("1")) 
        { 
         arropids1 += arropids.get(0) + ","; 


        System.out.println("arropids1"+arropids1); 

       } 
       } 
+0

データから解析された各arropids1を保存しますか? –

+0

はい...保存した後に私は各arropids1を分割したい... – RaagaSudha

答えて

2

あなたは文字列を初期化してhaventのようにして、NullPointerExceptionが取得する必要があり、それはあなたの問題を解決します

String arropids1=""; 

としてそれを初期化しますが、私はいけませんこのタスクではStringをImmutable型として推奨しますが、この目的でStringBufferを使用することができますので、次のコードを使用することをおすすめします:

static ArrayList<ArrayList<String>> listhere; 
ArrayList<String> arropids; 

StringBuffer buffer=new StringBuffer(); 

    for(int q=0;q<listhere.size();q++) 
       { 
        arropids = listhere.get(q); 

        if(arropids.get(3).equals("1")) 
        { 
         buffer.append(arropids.get(0)); 
         buffer.append(","); 


        System.out.println("arropids1"+arropids1); 

       } 
       } 

、最後にすることによって、そのバッファから文字列を取得します:ループのために、あなたが格納されている文字列のsplitメソッドを使用して文字列にその同じ設定であなたのパースを保存した後の結果を分割するために

String arropids1=buffer.toString(); 
+0

こんにちは、ありがとう...それはうまく動作しています – RaagaSudha

0

このような配列:

static ArrayList<ArrayList<String>> listhere; 
ArrayList<String> arropids; 
String arropids1 = ""; 


for(int q=0;q<listhere.size();q++) { 
       arropids = listhere.get(q); 

       if(arropids.get(3).equals("1")) 
       { 
        arropids1 += arropids.get(0) + ","; 


       System.out.println("arropids1"+arropids1); 

       } 
     } 
     String[] results = arropids1.split(","); 
     for (int i =0; i < results.length; i++) { 
      System.out.println(results[i]); 
     } 

これはあなたが探していることを望みます。

+0

こんにちはありがとう...それはうまくいきます..... – RaagaSudha

+0

あなたは答えをupvoteしてください?ありがとうございました –

関連する問題