1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<!--NewPage--> 3<HTML> 4<HEAD> 5<!-- Generated by javadoc (build 1.6.0-google-internal) on Mon Jan 04 20:47:57 PST 2010 --> 6<TITLE> 7Collections2 (Guava Libraries 2010.01.04) 8</TITLE> 9 10<META NAME="date" CONTENT="2010-01-04"> 11 12<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style"> 13 14<SCRIPT type="text/javascript"> 15function windowTitle() 16{ 17 if (location.href.indexOf('is-external=true') == -1) { 18 parent.document.title="Collections2 (Guava Libraries 2010.01.04)"; 19 } 20} 21</SCRIPT> 22<NOSCRIPT> 23</NOSCRIPT> 24 25</HEAD> 26 27<BODY BGCOLOR="white" onload="windowTitle();"> 28<HR> 29 30 31<!-- ========= START OF TOP NAVBAR ======= --> 32<A NAME="navbar_top"><!-- --></A> 33<A HREF="#skip-navbar_top" title="Skip navigation links"></A> 34<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> 35<TR> 36<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> 37<A NAME="navbar_top_firstrow"><!-- --></A> 38<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> 39 <TR ALIGN="center" VALIGN="top"> 40 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> 41 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> 42 <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> 43 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/Collections2.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> 44 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> 45 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> 46 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> 47 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> 48 </TR> 49</TABLE> 50</TD> 51<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> 52</EM> 53</TD> 54</TR> 55 56<TR> 57<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 58 <A HREF="../../../../com/google/common/collect/ClassToInstanceMap.html" title="interface in com.google.common.collect"><B>PREV CLASS</B></A> 59 <A HREF="../../../../com/google/common/collect/ComparisonChain.html" title="class in com.google.common.collect"><B>NEXT CLASS</B></A></FONT></TD> 60<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 61 <A HREF="../../../../index.html?com/google/common/collect/Collections2.html" target="_top"><B>FRAMES</B></A> 62 <A HREF="Collections2.html" target="_top"><B>NO FRAMES</B></A> 63 <SCRIPT type="text/javascript"> 64 <!-- 65 if(window==top) { 66 document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>'); 67 } 68 //--> 69</SCRIPT> 70<NOSCRIPT> 71 <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A> 72</NOSCRIPT> 73 74 75</FONT></TD> 76</TR> 77<TR> 78<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 79 SUMMARY: NESTED | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD> 80<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 81DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD> 82</TR> 83</TABLE> 84<A NAME="skip-navbar_top"></A> 85<!-- ========= END OF TOP NAVBAR ========= --> 86 87<HR> 88<!-- ======== START OF CLASS DATA ======== --> 89<H2> 90<FONT SIZE="-1"> 91com.google.common.collect</FONT> 92<BR> 93Class Collections2</H2> 94<PRE> 95<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</A> 96 <IMG SRC="../../../../resources/inherit.gif" ALT="extended by "><B>com.google.common.collect.Collections2</B> 97</PRE> 98<HR> 99<DL> 100<DT><PRE>public final class <B>Collections2</B><DT>extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></DL> 101</PRE> 102 103<P> 104Provides static methods for working with <code>Collection</code> instances. 105<P> 106 107<P> 108<DL> 109<DT><B>Since:</B></DT> 110 <DD>2010.01.04 <b>stable</b> (imported from Google Collections Library)</DD> 111<DT><B>Author:</B></DT> 112 <DD>Chris Povirk, Mike Bostock, Jared Levy</DD> 113</DL> 114<HR> 115 116<P> 117 118<!-- ========== METHOD SUMMARY =========== --> 119 120<A NAME="method_summary"><!-- --></A> 121<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 122<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> 123<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"> 124<B>Method Summary</B></FONT></TH> 125</TR> 126<TR BGCOLOR="white" CLASS="TableRowColor"> 127<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 128<CODE>static 129<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY=""> 130<TR ALIGN="right" VALIGN=""> 131<TD NOWRAP><FONT SIZE="-1"> 132<CODE><E> <A HREF="http://java.sun.com/javase/6/docs/api/java/util/Collection.html?is-external=true" title="class or interface in java.util">Collection</A><E></CODE></FONT></TD> 133</TR> 134</TABLE> 135</CODE></FONT></TD> 136<TD><CODE><B><A HREF="../../../../com/google/common/collect/Collections2.html#filter(java.util.Collection, com.google.common.base.Predicate)">filter</A></B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/util/Collection.html?is-external=true" title="class or interface in java.util">Collection</A><E> unfiltered, 137 <A HREF="../../../../com/google/common/base/Predicate.html" title="interface in com.google.common.base">Predicate</A><? super E> predicate)</CODE> 138 139<BR> 140 Returns the elements of <code>unfiltered</code> that satisfy a predicate.</TD> 141</TR> 142<TR BGCOLOR="white" CLASS="TableRowColor"> 143<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 144<CODE>static 145<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY=""> 146<TR ALIGN="right" VALIGN=""> 147<TD NOWRAP><FONT SIZE="-1"> 148<CODE><F,T> <A HREF="http://java.sun.com/javase/6/docs/api/java/util/Collection.html?is-external=true" title="class or interface in java.util">Collection</A><T></CODE></FONT></TD> 149</TR> 150</TABLE> 151</CODE></FONT></TD> 152<TD><CODE><B><A HREF="../../../../com/google/common/collect/Collections2.html#transform(java.util.Collection, com.google.common.base.Function)">transform</A></B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/util/Collection.html?is-external=true" title="class or interface in java.util">Collection</A><F> fromCollection, 153 <A HREF="../../../../com/google/common/base/Function.html" title="interface in com.google.common.base">Function</A><? super F,T> function)</CODE> 154 155<BR> 156 Returns a collection that applies <code>function</code> to each element of 157 <code>fromCollection</code>.</TD> 158</TR> 159</TABLE> 160 <A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A> 161<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 162<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"> 163<TH ALIGN="left"><B>Methods inherited from class java.lang.<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></B></TH> 164</TR> 165<TR BGCOLOR="white" CLASS="TableRowColor"> 166<TD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang">clone</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang">equals</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang">finalize</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang">getClass</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang">hashCode</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang">notify</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang">notifyAll</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang">toString</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang">wait</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang">wait</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait(long, int)" title="class or interface in java.lang">wait</A></CODE></TD> 167</TR> 168</TABLE> 169 170<P> 171 172<!-- ============ METHOD DETAIL ========== --> 173 174<A NAME="method_detail"><!-- --></A> 175<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 176<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> 177<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"> 178<B>Method Detail</B></FONT></TH> 179</TR> 180</TABLE> 181 182<A NAME="filter(java.util.Collection, com.google.common.base.Predicate)"><!-- --></A><H3> 183filter</H3> 184<PRE> 185public static <E> <A HREF="http://java.sun.com/javase/6/docs/api/java/util/Collection.html?is-external=true" title="class or interface in java.util">Collection</A><E> <B>filter</B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/util/Collection.html?is-external=true" title="class or interface in java.util">Collection</A><E> unfiltered, 186 <A HREF="../../../../com/google/common/base/Predicate.html" title="interface in com.google.common.base">Predicate</A><? super E> predicate)</PRE> 187<DL> 188<DD>Returns the elements of <code>unfiltered</code> that satisfy a predicate. The 189 returned collection is a live view of <code>unfiltered</code>; changes to one 190 affect the other. 191 192 <p>The resulting collection's iterator does not support <code>remove()</code>, 193 but all other collection methods are supported. The collection's 194 <code>add()</code> and <code>addAll()</code> methods throw an 195 <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang"><CODE>IllegalArgumentException</CODE></A> if an element that doesn't satisfy the 196 predicate is provided. When methods such as <code>removeAll()</code> and 197 <code>clear()</code> are called on the filtered collection, only elements that 198 satisfy the filter will be removed from the underlying collection. 199 200 <p>The returned collection isn't threadsafe or serializable, even if 201 <code>unfiltered</code> is. 202 203 <p>Many of the filtered collection's methods, such as <code>size()</code>, 204 iterate across every element in the underlying collection and determine 205 which elements satisfy the filter. When a live view is <i>not</i> needed, 206 it may be faster to copy <code>Iterables.filter(unfiltered, predicate)</code> 207 and use the copy. 208<P> 209<DD><DL> 210</DL> 211</DD> 212</DL> 213<HR> 214 215<A NAME="transform(java.util.Collection, com.google.common.base.Function)"><!-- --></A><H3> 216transform</H3> 217<PRE> 218public static <F,T> <A HREF="http://java.sun.com/javase/6/docs/api/java/util/Collection.html?is-external=true" title="class or interface in java.util">Collection</A><T> <B>transform</B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/util/Collection.html?is-external=true" title="class or interface in java.util">Collection</A><F> fromCollection, 219 <A HREF="../../../../com/google/common/base/Function.html" title="interface in com.google.common.base">Function</A><? super F,T> function)</PRE> 220<DL> 221<DD>Returns a collection that applies <code>function</code> to each element of 222 <code>fromCollection</code>. The returned collection is a live view of <code>fromCollection</code>; changes to one affect the other. 223 224 <p>The returned collection's <code>add()</code> and <code>addAll()</code> methods 225 throw an <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/UnsupportedOperationException.html?is-external=true" title="class or interface in java.lang"><CODE>UnsupportedOperationException</CODE></A>. All other collection 226 methods are supported, as long as <code>fromCollection</code> supports them. 227 228 <p>The returned collection isn't threadsafe or serializable, even if 229 <code>fromCollection</code> is. 230 231 <p>When a live view is <i>not</i> needed, it may be faster to copy the 232 transformed collection and use the copy. 233<P> 234<DD><DL> 235</DL> 236</DD> 237</DL> 238<!-- ========= END OF CLASS DATA ========= --> 239<HR> 240 241 242<!-- ======= START OF BOTTOM NAVBAR ====== --> 243<A NAME="navbar_bottom"><!-- --></A> 244<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A> 245<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> 246<TR> 247<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> 248<A NAME="navbar_bottom_firstrow"><!-- --></A> 249<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> 250 <TR ALIGN="center" VALIGN="top"> 251 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> 252 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> 253 <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> 254 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/Collections2.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> 255 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> 256 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> 257 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> 258 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> 259 </TR> 260</TABLE> 261</TD> 262<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> 263</EM> 264</TD> 265</TR> 266 267<TR> 268<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 269 <A HREF="../../../../com/google/common/collect/ClassToInstanceMap.html" title="interface in com.google.common.collect"><B>PREV CLASS</B></A> 270 <A HREF="../../../../com/google/common/collect/ComparisonChain.html" title="class in com.google.common.collect"><B>NEXT CLASS</B></A></FONT></TD> 271<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 272 <A HREF="../../../../index.html?com/google/common/collect/Collections2.html" target="_top"><B>FRAMES</B></A> 273 <A HREF="Collections2.html" target="_top"><B>NO FRAMES</B></A> 274 <SCRIPT type="text/javascript"> 275 <!-- 276 if(window==top) { 277 document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>'); 278 } 279 //--> 280</SCRIPT> 281<NOSCRIPT> 282 <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A> 283</NOSCRIPT> 284 285 286</FONT></TD> 287</TR> 288<TR> 289<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 290 SUMMARY: NESTED | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD> 291<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 292DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD> 293</TR> 294</TABLE> 295<A NAME="skip-navbar_bottom"></A> 296<!-- ======== END OF BOTTOM NAVBAR ======= --> 297 298<HR> 299 300</BODY> 301</HTML> 302