mam dane pobrane z mojego usługa wArrayList <HashMap <String, String >> do String []
ArrayList<HashMap<String,String>>
Teraz chcę przekonwertować każdy przedmiot wyżej
String[]
jak czy to zrobię? każda pomoc będzie bardzo ceniona!
mam dane pobrane z mojego usługa wArrayList <HashMap <String, String >> do String []
ArrayList<HashMap<String,String>>
Teraz chcę przekonwertować każdy przedmiot wyżej
String[]
jak czy to zrobię? każda pomoc będzie bardzo ceniona!
spróbować
ArrayList<HashMap<String, String>> test = new ArrayList<HashMap<String, String>>();
HashMap<String, String> n = new HashMap<String, String>();
n.put("a", "a");
n.put("b", "b");
test.add(n);
HashMap<String, String> m = test.get(0);//it will get the first HashMap Stored in array list
String strArr[] = new String[m.size()];
int i = 0;
for (HashMap<String, String> hash : test) {
for (String current : hash.values()) {
strArr[i] = current;
i++;
}
}
Zastosowania dla Hashmap powinny być indeksem wartości HashValues w celu znalezienia wartości znacznie szybciej. Nie wiem, dlaczego masz klucza i wartości jako ciągi znaków, ale jeśli trzeba tylko wartości można to zrobić tak:
ArrayList<HashMap<String, String>> test = new ArrayList<>();
String sum = "";
for (HashMap<String, String> hash : test) {
for (String current : hash.values()) {
sum = sum + current + "<#>";
}
}
String[] arr = sum.split("<#>");
To nie jest dobry sposób, ale wniosek nie jest to zbyt;)
dziękuję, że działa :) –
ArrayList<HashMap<String, String>> meterList = controller.getMeter();
HashMap<String, String> mtiti = meterList.get(0);//it will get the first HashMap Stored in array list
String[] strMeter = new String[mtiti.size()];
String meter = "";
for (HashMap<String, String> hash : meterList) {
for (String current : hash.values()) {
meter = meter + current + "<#>";
}
}
String[] arr = meter.split("<#>");
zawiera dane uzyskane od usługa obsługującego dane jSON. muszę wyodrębnić każde pole jako tablicę ciągów, aby zapełnić je różnymi widokami, takimi jak viwepagers i widoki list. –
http://stackoverflow.com/questions/1090556/java-how-to-convert-hashmapstring-object-to-array.check to może pomóc. – Raghunandan
W tablicy chcesz umieścić klucze, wartości lub oba klucze? – Alberto