Java: how to convert a List<?> to a Map<String,?> [duplicate]
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: This question already has an answer here: Java: How to convert List to Map 16 answers I would like to find a way to take the object specific routine below and abstract it into a method that you can pass a class, list, and fieldname to get back a Map. If I could get a general pointer on the pattern used or , etc that could get me started in the right direction. Map < String , Role > mapped_roles = new HashMap < String , Role >(); List < Role > p_roles = ( List < Role >) c . list (); for ( Role el : p_roles ) { mapped_roles . put (