parsing a comparable to a string...
ok, so heres what i have...
Code:
Comparable nodeInput = JOptionPane.showInputDialog(null);
i just need to know what line of code i would need to use if i wanted to parse that to an integer...
i have tried the following...
Code:
tree.insert(new Integer(Integer.parseInt(nodeInput)));
the error i get is that my IDE says that the symbol method parseInt could not be found...
thanks for any help in advance.
Re: parsing a comparable to a string...
That is because the Integer has two parseInt methods. One takes a string, and the other takes a String and an int. There is not a parseInt method that takes a Comparable object.
Strings are already Comparable and showInputDialog does return a String object, so why not use Strings?
Re: parsing a comparable to a string...
that worked perfect, I was under the impression that i had to use comparables, because im utilising another class called BinarySearchTree, and it uses comparables...
thanks for the help!
Re: parsing a comparable to a string...
Yes, and since the String class Implements Comparable it can be used as a Comparable object. That means it can be passed around as a Comparable object and hence why your code :Comparable c = JOp... worked.