Results 1 to 6 of 6

Thread: Comparison two Class values in java

  1. #1
    Join Date
    Dec 2009
    Posts
    202

    Comparison two Class values in java

    Hello,
    I would like to compare two values that I recover in a java class. So I did a System.out.println, I've recovered well, now I'd like to compare:
    Here's the code:
    Code:
    BigDecimal val1 = Classe.1getData1();
    BigDecimal val2 = class2.getData2();
    I'd like to compare these two values 1 and 2 as follows: value1 > value2
    but I tried
    Code:
    val1.CompareTo(val2)
    but this does not work. Any idea on this is appreciated.

  2. #2
    Join Date
    Nov 2009
    Posts
    343

    Re: Comparison two Class values in java

    Hello,
    For obtaining this
    Code:
    BigDecimal val1 = Classe.1getData1();
    BigDecimal val2 = class2.getData2();
    You should do something like this.
    Code:
    if (value1.compareTo(value2) > 0) {
      System.out.System.out.println("test ok");
    } / / Otherwise nothing
    I think this should work perfectly, just have a try to it.

  3. #3
    Join Date
    Dec 2009
    Posts
    202

    Re: Comparison two Class values in java

    Hello,
    if (value1.compareTo(value2) > 0) { System.out.System.out.println("test ok"); } / / Otherwise nothing
    or it works this:
    Code:
    Boolean t;
    Or something like this
    Code:
    if (value1.compareTo(value2) > 0) 
    { 
        t =true; 
    }
    compareTo but does AC compare that value1 is greater than value2 but not to Zero?

  4. #4
    Join Date
    Nov 2009
    Posts
    356

    Re: Comparison two Class values in java

    Hello,
    I will try to explain you this.
    Code:
    Car c = new Car();
    Now the result is
    Code:
    Print(c instanceof Car); //true
    Print(c instanceof Car2); //false
    But if you are following the concept of inheritance, then
    Code:
    Print(c instanceof Car); //true
    Print(c instanceof Vehicle); //true
    This is because
    Code:
    Vehicle a = new Car();
    Print(a instanceof Car); //true;
    Print(a instanceof Vehicle); //true
    Hope you understood the concept behind it.

  5. #5
    Join Date
    Dec 2009
    Posts
    211

    Re: Comparison two Class values in java

    Hey,
    I am having a similar kind of a problem.
    Here is my code, please check it and if you think this is wrong then please guide me with the correct.
    Code:
    Boolean rs = false;
    if (value1.compareTo(value2) > 0) 
    { 
        rs = false; 
    }
    Any help on this will be highly appreciated. Thanks in advance.

  6. #6
    Join Date
    Dec 2009
    Posts
    178

    Re: Comparison two Class values in java

    Hello,
    I am learning this concept now, I do not know what exactly you want, but I have a code with me that compares two strings, see if helps you are you can get an idea from it.
    Here is the code:
    Code:
    String str1 = "test";
    String str2 = "TEST";
    
    // java str compare 
    if (str1.equalsIgnoreCase(str2))
    {
      // this line WILL print
      System.out.println("Ignoring case, the two strs are the same.")
    }

Similar Threads

  1. Converting Boolean values to string in Java
    By 27lynx27 in forum Software Development
    Replies: 1
    Last Post: 13-02-2011, 03:40 AM
  2. Converting java class to java bean class
    By Ucchal in forum Software Development
    Replies: 6
    Last Post: 09-08-2010, 10:24 AM
  3. Retrieve multiple values from java class
    By Ash maker in forum Software Development
    Replies: 5
    Last Post: 13-02-2010, 12:05 AM
  4. Comparison between core java and advanced java
    By Prashobh Mallu in forum Software Development
    Replies: 5
    Last Post: 19-01-2010, 10:57 AM
  5. How to set default Java parameter values
    By StudyBoy in forum Software Development
    Replies: 3
    Last Post: 03-03-2009, 03:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,869,164.47794 seconds with 16 queries