2011-12-19 12 views
-1

私は文字列の配列を持っています。どのようにMap(String、Object)に変換しますか?私はそれをデータオブジェクトに変換する必要があります。マップする文字列の配列

+1

:あなただけString[]がサイズ変更可能な配列になりたい場合は

String[] strs = new String[]; //Your string array, initialized elsewhere Object[] os = new Object[]; //The objects that you want mapped. Map<String, Object> m = new HashMap<String, Object>(); // I use HashMap because it is the most generic for(int i = 0; i < strs.length; i++) { m.put(strs[i], os[i]); //Add each object, os[i], to the map at position str[i] } 

は、あなたがこれを使用することができます各文字列の値をマップする_to_? –

+0

あなたはどんな種類のマッピングをしようとしているのか詳しく説明できますか? –

答えて

0

Mapの使用は、associative arrayに相当します。これにあなたのケースを適用すると、それぞれStringが別のObjectを指していることになります。これはあなたが望むものである場合

、これは動作します:あなたがしたいです何

List<String> a = Arrays.asList(strs);