java - use Enumerations in for-each statements without RAM limitation? -


hi have 10 million values , getting enumeration in enhanced-for loop, blasts ram. there way iteration rather enumeration.

i trying to find alternate collections.list() , collections.enumeration().

import java.util.collections; import java.util.enumeration; import java.util.iterator; public final class enumerations {      /**      * allows using of {@link enumeration} for-each statement.      * implementation not using heap space , such able serve      * virtually endless enumerations, while {@link collections#list} limited      * available ram. result, implementation faster      * collections.list.      *       * @param enumeration      *            original enumeration.      * @return {@link iterable} directly calling original enumeration.      */     public static final <t> iterable<t> iterable(final enumeration<t> enumeration) {         return new iterable<t>() {             public final iterator<t> iterator() {                 return new iterator<t>() {                     public final boolean hasnext() {                         return enumeration.hasmoreelements();                     }                      public final t next() {                         return enumeration.nextelement();                     }                      /**                      * method not implemeted impossible                      * remove enumeration.                      *                       * @throws unsupportedoperationexception                      *             always.                      */                     public final void remove() {                         throw new unsupportedoperationexception();                     }                 };             }         };     }  } 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -