gpt4 book ai didi

java - 去掉 hashmap 中的逗号

转载 作者:行者123 更新时间:2023-12-01 15:23:13 26 4
gpt4 key购买 nike

我在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 中,但事实并非如此。所有值都存储在第一个索引本身中。

其次,即使我尝试 fork ,我也找不到合适的方法。首先我想到通过“,”运算符拆分字符串,但字符串本身包含多个“,”

请建议我应该针对第一个问题做什么,我不希望所有值都为单个字符串。

谢谢

日志:

                                    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

最佳答案

我尝试理解代码。我怀疑问题在于 map 对象以及如何为其填充数据。根据您的声明,您的 map 可能只有 1 个带有长字符串的条目。

所以...至少,您可以发布 map 数据填充的代码。希望解决这个问题不会那么困难。

关于java - 去掉 hashmap 中的逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10561718/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com