2012-05-12 6 views
0

私はJavaのHashmapでキー値のペアを持っています。私は次のようにMapをトラバースしています。ハッシュマップでコンマを取り除く

ArrayList<String> mysection = new ArrayList<String>(); 
    ArrayList<String> temp = new ArrayList<String>(); 

    Iterator it = Map.entrySet().iterator(); 

    while (it.hasNext()){ 
     Map.Entry pairs = (Map.Entry)it.next();     
     System.out.println(" = " + pairs.getValue());     

     mysection.add(pairs.getKey().toString()); 
     temp.add(pairs.getValue().toString()); 

     it.remove(); // avoids a ConcurrentModificationException   

    } 

これは良いようですが、ループは一度実行され、キーに関連付けられた値の長い文字列を作成します。私はそのようにしたくない。私は各値をArrayListに格納したいが、それはこのように起こっていない。すべての値は、最初のインデックス自体に格納されます。

二番目に分岐しても、私は適切な方法を見つけることができません。最初に私は文字列を "、"演算子で分割することを考えましたが、文字列自体に複数の "、"が含まれていました

第1質問に対して特に何をすべきかを提案してください。

おかげ

ログイン:ここ

        05-12 12:14:01.387: I/System.out(433): EAMCET: caution on punctuality, 
      05-12 12:14:01.387: I/System.out(433): Delay by even a minute can cost one year for the aspirants, warn the officials making it clear that they need to report at least 45 minutes in advance for the EAMCET to be held on May 12. Th... 
      05-12 12:14:01.387: I/System.out(433): , 
      05-12 12:14:01.387: I/System.out(433): Shankar Rao takes on Kiran , 
      05-12 12:14:01.387: I/System.out(433): Former Minister P. Shankar Rao on Friday opened a new front in his fight against Chief Minister N. Kiran Kumar Reddy by submitting a notice of breach of privilege against the latter for preventing... 
      05-12 12:14:01.387: I/System.out(433): , 
      05-12 12:14:01.458: I/System.out(433): Police fear more Maoist attacks , 
      05-12 12:14:01.458: I/System.out(433): Uneasy calm prevails in villages tucked away along the shores of the Godavari adjoining neighbouring Chhattisgarh after the Maoists conducted a â??Praja Courtâ? in the interior Mukunur village of Maha... 
      05-12 12:14:01.458: I/System.out(433): , 
      05-12 12:14:01.458: I/System.out(433): 'Science in danger of regressing' , 
      05-12 12:14:01.458: I/System.out(433): Askok Ganguly delivers 'A.V. Rama Rao Tech Award Lecture' 
      05-12 12:14:01.458: I/System.out(433): , 
      05-12 12:14:01.458: I/System.out(433): Global firms pick up ISB students , 
      05-12 12:14:01.458: I/System.out(433): Average annual salary offered is Rs.18.83 lakh, 8 p.c. more than last year 
      05-12 12:14:01.458: I/System.out(433): , 
      05-12 12:14:01.458: I/System.out(433): Telugu varsity to make its courses job-oriented, 
      05-12 12:14:01.458: I/System.out(433): Potti Sreeramulu Telugu University is planning to attract more students to pursue higher education by offering employment oriented courses.The university was exploring chances to embed info... 
      05-12 12:14:01.458: I/System.out(433): , 
      05-12 12:14:01.458: I/System.out(433): Kiran sharpens attack on Jagan, 
      05-12 12:14:01.458: I/System.out(433): Ruling Congress has launched a three-cornered attack on its two arch rivals -- YSRCP president Y.S. Jaganmohan Reddy and TDP chief N. Chandrababu Naidu at Tirupati on Friday in its run up to the b... 
      05-12 12:14:01.458: I/System.out(433): , 
      05-12 12:14:01.458: I/System.out(433): RINL to get Central nod soon for mining in Rajasthan, 
      05-12 12:14:01.458: I/System.out(433): The Centre will give its nod soon for granting lease for iron ore mining to Rashtriya Ispat Nigam Limited (RINL), the corporate entity of Visakhapatnam Steel Plant. 
      05-12 12:14:01.458: I/System.out(433): â??After the Rajasthan g... 

は、出力のイメージは次のとおりです。 enter image description here

+2

コードにtempとmysectionが何であるかを明確にするためのコードを追加する必要があります。 – Tom

+1

'mysection'や' temp'で何をしているのか分かりません。問題を示す短くしかし完全な*プログラム(ちょうど普通のJava)を与えてください。 –

+1

あなたはこの結論にどのように来るかを説明する必要があります。 –

答えて

0

OK、実際には完了しました...実際にマップを繰り返し処理する方法はたくさんありますが、これは私が望むものには最適ではありません。そこで、今や別の方法の反復のインプリケーションを変更しました。

1

私は、コードを理解しよう。 私は、マップオブジェクトに問題があると思われ、そのデータをどのように埋め込むのかを考えます。おそらくあなたのマップは、あなたのステートメントから長い文字列で1つだけのエントリを持っています。

だから少なくとも、地図データの人口に関するコードを投稿することができます。うまくいけばそれを固定することはそれほど難しくないでしょう。

関連する問題