CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2008
    Posts
    49

    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.

  2. #2
    Join Date
    Feb 2008
    Posts
    966

    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?

  3. #3
    Join Date
    Sep 2008
    Posts
    49

    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!

  4. #4
    Join Date
    Feb 2008
    Posts
    966

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured