Hot Posts

For loops using method calls and primitive wrapper objects

Method calls can be used instead of literals comparisons:

public class ForLoopsMethodCalls {
       public static void main(String [] arg){         
             for (int x = intValue(); test(x); x = go (x)){
                  System. out .println(x);
            }                 
      }
      
       public static Boolean test(int x){
             return new Boolean(x < 10);         
      }
      
       public static int intValue(){
             return 0;
      }
      
       public static int go(int x){
             return ++x;
      }           
}

Wrapper objects can be used where literals are used:

public class ForLoopsWrapperClasses {
       public static void main(String [] arg){         
             for (int x = Integer.valueOf(10); test(x); x = go(x)){
                  System.out.println(x);
            }           
      }
      
       public static Boolean test(int x){
             return new Boolean(x < 10);         
      }
      
       public static Integer go(int x){
             return new Integer(3);
      }                 
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: