我有这个 ArrayList
public ArrayList<HashMap<String, String>> xmlFileNames = new ArrayList<>();
Run Code Online (Sandbox Code Playgroud)
我想将其转换为:
HashMap<String, String> comparemap2 = new HashMap<>();
Run Code Online (Sandbox Code Playgroud)
我想要的是:我想要ArrayList中的所有Items并希望将它们放入HashMap我的HashMap看起来像:
核心价值
job_id 032014091029309130921.xml
job_id 201302149014021492929.xml
job_id 203921904901920952099.xml
编辑: 稍后我想将此地图与现有地图进行比较:
Properties properties = new Properties();
try {
properties.load(openFileInput("comparexml.kx_todo"));
} catch (IOException e) {
e.printStackTrace();
}
for (String key : properties.stringPropertyNames()) {
compareMap.put(key, properties.get(key).toString());
}
HashMap<String, String> oldCompareMap = new HashMap<>();
for (HashMap key : xmlFileNames) {
oldCompareMap.putAll(key);
}
isEqualMaps(oldCompareMap, compareMap);
Run Code Online (Sandbox Code Playgroud)
我只想比较,如果文件名存在于compareMap.如果没有,请将其添加到xmlFileName地图中
我已经在StackOverFlow中查找了,我如何将ArrayList转换为HashMap.但是其他线程会将数据类型视为Item或Product.
我希望你能帮帮我!
亲切的问候
我目前对 Map 何时优于 HashMap 或其他方式感到困惑,对于列表/数组列表也是如此...
有人可以请 ELI5 吗?我知道如何使用它们,但我需要有人在应该使用它们时为我清理它,谢谢。
有什么区别?请看下面.
HashMap<Integer, String> hashMap = new HashMap<Integer, String>();
Run Code Online (Sandbox Code Playgroud)
和
Map<Integer, String> hashMap = new HashMap<Integer, String();
Run Code Online (Sandbox Code Playgroud)
它们可以互换吗?
在一次采访中我被问到一个类似的问题:
从控制台获取输入,例如:"欢迎来到世界"并计算用户输入的特定字符,其中索引和次数(即字符的出现)不使用任何内置方法等
charAt(int ind).
为什么我们使用Runnable接口,即使它与start()方法没有关联?为什么我们不能只写run()方法并开始?
为什么我们需要实现run()方法,而不是直接使用它并使用start()方法启动进程?
以下代码提供了错误的信息:
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
public class test {
public static void main(String[] args) {
GregorianCalendar fmt = new GregorianCalendar(2000, 7, 3);
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
String result = df.format(fmt.getTime());
System.out.println("fmt: " + result);
}
}
Run Code Online (Sandbox Code Playgroud)
它输出:
fmt:2000年8月3日
虽然我需要月份为7月,因为我已将月份设定为7?