<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CADJEE Consulting &#187; CollectionUtils</title>
	<atom:link href="https://cadjee.fr/tag/collectionutils/feed/" rel="self" type="application/rss+xml" />
	<link>https://cadjee.fr</link>
	<description>Expertise Java &#38; Système d&#039;information</description>
	<lastBuildDate>Thu, 17 Dec 2015 21:37:19 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.39</generator>
	<item>
		<title>CollectionUtils, Predicate &amp; select</title>
		<link>https://cadjee.fr/collectionutils-predicate-select/</link>
		<comments>https://cadjee.fr/collectionutils-predicate-select/#comments</comments>
		<pubDate>Sun, 01 Feb 2015 14:11:50 +0000</pubDate>
		<dc:creator><![CDATA[Ismael CADJEE]]></dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[CollectionUtils]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[predicate]]></category>

		<guid isPermaLink="false">http://cadjee.fr/?p=13</guid>
		<description><![CDATA[La bibliothèque org.apache.commons.collections.CollectionUtils offre bien des services dont voici un : la recherche dans une collection par Prédicat. Il s’agit simplement de rechercher des éléments dans une collection ( List ) et de les stocker dans une liste de sortie grâce à la méthode select. Un exemple vaut mieux qu’un long discours: &#160; L’interface Predicate [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>La bibliothèque <strong>org.apache.commons.collections.CollectionUtils</strong> offre bien des services dont voici un : la recherche dans une collection par <em><strong>Prédicat</strong></em>.<span id="more-13"></span></p>
<p>Il s’agit simplement de rechercher des éléments dans une collection ( List ) et de les stocker dans une liste de sortie grâce à la méthode <em><strong>select</strong></em>.<br />
Un exemple vaut mieux qu’un long discours:</p>
<pre class="brush: java; title: ; notranslate">
public static void main(String[] args) {

    List&lt;String&gt; maListe = new ArrayList&lt;String&gt;();
        maListe.add(&quot;chat&quot;);
        maListe.add(&quot;chameau&quot;);
        maListe.add(&quot;chien&quot;);
        maListe.add(&quot;oie&quot;);
        maListe.add(&quot;humain&quot;);
        maListe.add(&quot;tigre&quot;);

        List&lt;String&gt; listeAnimalC = new ArrayList&lt;String&gt;();

      CollectionUtils.select(maListe, new Predicate() {

            public boolean evaluate(Object object) {
            String val =    (String) object;
            return val.startsWith(&quot;c&quot;);
            }
        },listeAnimalC);

        System.out.println(listeAnimalC);

    }
}
</pre>
<p>&nbsp;</p>
<div class="line number26 index25 alt1">L’interface <strong>Predicate</strong> doit définir la méthode <strong>evaluate</strong>. Cette méthode définit la condition qui sélectionnera l’élément de la collection initiale vers la collection de sortie.<br />
Dans notre exemple, on décide de conserver dans la liste de sortie les éléments débutant par la lettre « c ».<br />
La console de sortie affichera naturellement :</div>
<blockquote>
<div class="line number26 index25 alt1">[chat, chameau, chien]</div>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>https://cadjee.fr/collectionutils-predicate-select/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
