I want to pass myVector
to another class (Case.java
) but I get this kind of error message. Type mismatch: cannot convert from Object[] to int[]. Can anybody tell me how to solve this?
User.java
JButton btnNewButton = new JButton("Process");
btnNewButton.setBounds(360, 296, 89, 23);
contentPane.add(btnNewButton);
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Integer a = (comboBox.getSelectedIndex() + 1);
Integer b = (comboBox_1.getSelectedIndex() + 1);
Integer day = (comboBox_2.getSelectedIndex() + 1);
ArrayList<Integer> myVector = new ArrayList<Integer>();
myVector.add(a);
myVector.add(b);
myVector.add(day);
Case ca = new Case();
try {
ca.addPlace(myVector);
LoginGUI um = new LoginGUI();
um.setVisible(true);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
Case.java
public class Case {
public Case() {
// TODO Auto-generated constructor stub
}
public void addPlace(ArrayList<Integer> h) {
int vec1[] = h.toArray();
int vec2[] = {2, 1, 3, 2};
double cos_sim = cosine_similarity(vec1, vec2);
}
Pass a new array to the toArray
method. Like this:
Integer[] vec = h.toArray(new Integer[h.size()]);
With Java8 this would be possible:
int[] vec1 = h.stream().filter(t -> t != null).mapToInt(t -> t).toArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With