Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0

    Default Comparing null problem

    Hi, I have a problem with comparing Big Decimal with null
    Java Code:
    for (int x = 0; x < engagementList.size(); x++) {
    					if(engagementList.get(x).getOverall_aef() != null)
    						engagementList.remove(x);
    				}
    
    for(int a = 0; a < engagementList.size(); a++){
    			log.info("engagementList.get(a).getOverall_aef()="+engagementList.get(a).getOverall_aef());	
    		}
    Output:
    Java Code:
    INFO  2008-02-04 17:39:06,828 [EngagementAction.java:2989] engagementList.get(a).getOverall_aef()=null
    INFO  2008-02-04 17:39:06,828 [EngagementAction.java:2989] engagementList.get(a).getOverall_aef()=null
    INFO  2008-02-04 17:39:06,828 [EngagementAction.java:2989] engagementList.get(a).getOverall_aef()=null
    INFO  2008-02-04 17:39:06,843 [EngagementAction.java:2989] engagementList.get(a).getOverall_aef()=null
    INFO  2008-02-04 17:39:06,843 [EngagementAction.java:2989] engagementList.get(a).getOverall_aef()=null
    INFO  2008-02-04 17:39:06,843 [EngagementAction.java:2989] engagementList.get(a).getOverall_aef()=57.50
    INFO  2008-02-04 17:39:06,843 [EngagementAction.java:2989] engagementList.get(a).getOverall_aef()=null
    INFO  2008-02-04 17:39:06,843 [EngagementAction.java:2989] engagementList.get(a).getOverall_aef()=null
    INFO  2008-02-04 17:39:06,843 [EngagementAction.java:2989] engagementList.get(a).getOverall_aef()=null
    INFO  2008-02-04 17:39:06,843 [EngagementAction.java:2989] engagementList.get(a).getOverall_aef()=null
    INFO  2008-02-04 17:39:06,843 [EngagementAction.java:2989] engagementList.get(a).getOverall_aef()=null
    INFO  2008-02-04 17:39:06,859 [EngagementAction.java:2989] engagementList.get(a).getOverall_aef()=null
    INFO  2008-02-04 17:39:06,859 [EngagementAction.java:2989] engagementList.get(a).getOverall_aef()=null
    INFO  2008-02-04 17:39:06,859 [EngagementAction.java:2989] engagementList.get(a).getOverall_aef()=null
    an object with "Overall_aef" of 57.50 was not removed. Is it bad to compare with null? Is there any alternative?
    Thanx!

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    engagementList.get(x).getOverall_aef()
    Does this method return a BigDecimal?
    These work okay:
    Java Code:
            BigDecimal one = BigDecimal.ONE;
            System.out.println("one = " + one);
            System.out.printf("one == null = %b%n",
                               one == null);
            System.out.printf("one.equals(null) = %b%n",
                               one.equals(null));

  3. #3
    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by hardwired View Post
    engagementList.get(x).getOverall_aef()
    Does this method return a BigDecimal?
    Yes it returns a Big Decimal. How come my loop doesn't remove all Object(named Engagement) in my List(engagementList) with !null BigDecimal overall_aef?

    I've already solve my problem by search the database rather than filtering the List but I'm still mystified why my loop didn't work well.

Similar Threads

  1. Problem comparing three numbers
    By gammaman in forum New To Java
    Replies: 1
    Last Post: 02-09-2008, 05:43 PM
  2. Comparing problem
    By mcal in forum New To Java
    Replies: 1
    Last Post: 01-24-2008, 03:56 AM
  3. comparing
    By Feng in forum New To Java
    Replies: 2
    Last Post: 11-23-2007, 09:40 AM
  4. Problem with JTextFields not null
    By romina in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 05:17 AM
  5. Comparing types, integer with null
    By Felissa in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 06:32 AM

Posting Permissions

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