class swap {
public static void main(String[] args) throws FileNotFoundException {
Scanner s1 = new Scanner(new FileReader("C:/Users/USER/Desktop/Saumil/Saumil/FP.data"));
Scanner s2 = new Scanner(new FileReader("C:/Users/USER/Desktop/Saumil/Saumil/FP1.data"));
HashMap<String, String> map1 = new HashMap<String, String>();
HashMap<String, String> map2 = new HashMap<String, String>();
while (s1.hasNextLine()) {
String[] columns = s1.nextLine().split("");
System.out.println("hi");
map1.put(columns[0], columns[1]);
}
while (s2.hasNextLine()) {
String[] columns = s2.nextLine().split("");
System.out.println("123");
map1.put(columns[0], columns[1]);
}
System.out.println(map1);
try {
//Map result = new HashMap();
Set<String> s = new HashSet<String>(map1.keySet());
System.out.println("1234");
s.retainAll(map2.keySet());
System.out.println(s);
FileOutputStream fos = new FileOutputStream("C:/Users/USER/Desktop/Saumil/Saumil/output.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(s); // write list to ObjectOutputStream
oos.close();
System.out.println("hi");
} catch(Exception ex) {
ex.printStackTrace();
}
//Collection intersection=CollectionUtils.intersection(map1.keySet(),map2.keySet());
s1.close();
s2.close();
Я пытаюсь пересечь две хэш-карты. Каждая хэш-карта получает свои данные из файла, который имеет в основном два столбца.ArrayIndexOutofBoundException в HashMap для setintersection
его дает мне arrayindexout связанного исключения в строке no: -14 i.e map1.put (столбцы [0], столбцы [1]);
я не понимаю, почему это дает мне такое исключение
Исключение в потоке "основного" java.lang.ArrayIndexOutOfBoundsException: 1 \t в swap.main (swap.java:14) а именно: - map1.put (столбцы [0], столбцы [1]); –
отредактируйте этот вопрос. код не полностью сформирован, нет stacktrace, даже немного описания о точной проблеме ... – Paul
Я новичок в этом, может сказать, как отредактировать вопрос –