java - android: HashMap 变量

标签 java android hashmap

我知道这是一个菜鸟问题,但我无法在网上找到任何东西。我有这个 HashMap :

HashMap<String, String> map = new HashMap<String, String>();
        Element e = (Element) children.item(i);
        map.put("title", ParseXMLmethods.getValue(e, "title"));
        map.put("pubDate", ParseXMLmethods.getValue(e, "pubDate"));
        map.put("link", ParseXMLmethods.getValue(e, "link"));
        map.put("description",ParseXMLmethods.getValue(e, "description"));
        localist.add(map);

我收到有关本地化的错误消息:“无法解析本地化”。我知道我必须声明本地化但我不知道要使用哪种变量类型。非常感谢任何帮助。

最佳答案

首先,将您的 Map 变量声明为接口(interface) Map 并将它们初始化为实现,例如

Map<String, String> map = new HashMap<String, String>();

您还可以使用菱形运算符 <> 来推断模板类型,例如

HashMap<String, String> map = new HashMap<>();

虽然以上内容不是必需的,但它们是很好的做法。 现在,要声明本地化,您可以执行以下操作:

List<Map<String, String>> localist = new ArrayList<>();

这是将字符串映射到字符串的映射列表。

关于java - android: HashMap 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19039101/

相关文章:

java - Swing - 在运行时更改菜单栏和菜单项字体大小

java - libgdx gdx-setup.jar 构建失败

java - 整理导入打扰评论

android - 解析 getLayoutInflater 时出错(未定义)

android - setParameters 异常...无法使用相机

android - ListView 中的 "Separators"

javascript - 哈希键/值作为数组

java - 带有整数的集合,需要自行增减

java - searchByEmail 方法不起作用

java - 悬停时显示单词含义,可用作 MT 系统的后期编辑工具