Cant get Object String value (Need to convert to String for Compare) : I want to check if the value does exist or not in JTree when trying to add node from Jtree.
(the values does not match case i got object code not string)


Here is the action code for calling existsInTable()

         try {
            DefaultMutableTreeNode selectedElement = (DefaultMutableTreeNode) TestTree.getSelectionPath().getLastPathComponent();
            Object[] row = {selectedElement};
            DefaultTableModel model = (DefaultTableModel) myTests_table.getModel();

            if (selectedElement.isLeaf() == true && existsInTable(myTests_table, row) == false) {
                model.addRow(row);
            } else {
                JOptionPane.showMessageDialog(null, "Please Choose Test name!", "Error", JOptionPane.WARNING_MESSAGE);
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error");
        }


Here are the Check method

        public boolean existsInTable(JTable table, Object[] testname) {
        int row = table.getRowCount();
           for (int i = 0; i < row; i++) {
            String str = "";
            str = table.getValueAt(i, 0).toString();
            if (testname.equals(str)) {
                System.out.println(str);
                JOptionPane.showMessageDialog(null, "data alreadyexist.", "message", JOptionPane.PLAIN_MESSAGE);
                return true;
            }
        }
        return false;

    }