我打印出存儲在地圖中的字符串值,但我不希望它打印[]或分隔符。如何僅打印值?如何在沒有[...]和分隔符的地圖中打印出值(字符串)?
Iterator<String> iterator = styles.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next().toString();
String value = styles.get(key).toString();
stylePlaceHolder = value + "\n";
}
siteElements.add(stylePlaceHolder);
Iterator<String> iterator2 = libraries.keySet().iterator();
while (iterator2.hasNext()) {
String key = iterator2.next().toString();
String value = libraries.get(key).toString();
libPlaceHolder = value + "\n";
System.out.println(libraries.values().toString());
}
生成:
03-23 17:56:56.350: I/System.out(9642143): [<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
03-23 17:56:56.350: I/System.out(9642143):
, <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.
min.css" />
03-23 17:56:56.350: I/System.out(9642143): , <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
03-23 17:56:56.350: I/System.out(9642143):
]
您可以循環更efficently在使用'entrySet'方法遍歷entryies地圖。您甚至可以使用增強型for循環 - for(最終條目條目:myMap.entrySet())'。 –
2013-03-23 21:14:26