title: java + increasing performance and scalability
body: <p>below is the a code snippet, which returns the object of a class. now the object is basially comparing to some parameter in loop.</p>
  
  <p>my concern is what if there are thousands of objects in loop, in that case performance and scalability can be an issue. please suggest how to improve this code for performance part</p>
  
  <pre><code>public Widget get(String name,int major,int minor,boolean exact) {
     Widget widgetToReturn = null;
     if(exact) {
         Widget w = new Widget(name, major, minor);
  
         // for loop using JDK 1.5 version
         for(Widget wid : set) {
              if((w.getName().equals(wid.getName())) &amp;&amp; (wid.getVersion()).equals(w.getVersion())) {
                  widgetToReturn = w;
                  break;
              } 
         }
     } else {
         Widget w = new Widget(name, major, minor);
         WidgetVersion widgetVersion = new WidgetVersion(major, minor);
  
         // for loop using JDK 1.5 version
         for(Widget wid : set) {
             WidgetVersion wv = wid.getVersion();
             if((w.getName().equals(wid.getName())) &amp;&amp; major == wv.getMajor() &amp;&amp; WidgetVersion.isCompatibleAndNewer(wv, widgetVersion)) {
                  widgetToReturn = wid;
             } else if((w.getName().equals(wid.getName())) &amp;&amp; wv.equals(widgetVersion.getMajor(), widgetVersion.getMinor())) {
                  widgetToReturn = w;
             }
         }
     }
     return widgetToReturn;
  </code></pre>
  
  <p>}</p>