{"id":398,"date":"2023-11-23T08:51:34","date_gmt":"2023-11-23T07:51:34","guid":{"rendered":"https:\/\/www.rothamel.com\/?p=398"},"modified":"2023-11-23T08:51:34","modified_gmt":"2023-11-23T07:51:34","slug":"collections-and-streams","status":"publish","type":"post","link":"https:\/\/www.rothamel.com\/index.php\/2023\/11\/23\/collections-and-streams\/","title":{"rendered":"Collections and streams"},"content":{"rendered":"\n<p>An interesting way to process a collection is the usage of streams. A stream provides a sequential access to the elements of the collection. Below a code snipped for a simple selection of elements of an existing collection.<\/p>\n\n\n\n<p>In this example the dataList contains just some Strings and we want to get a new list of all Strings, that contain a specific char sequence.<\/p>\n\n\n\n<p><code>List&lt;String> myFancyList = dataList<\/code><br>   <code>.stream()<\/code><br>   <code>.filter(e -> e.contains(\"whatever\"))<\/code><br>   <code>.collect(Collectors.toList());<\/code><\/p>\n\n\n\n<p>Well, thats just an easy example, you will definitely find a more worthful usage in your projects \ud83d\ude09<\/p>\n\n\n\n<p>It&#8217;s getting a little bit more tricky, if you want to get a list with different types. Eg. if you want to select by a filter condition and want all the matching elements converted to a different type. Therefore the forEach method is quite usable:<\/p>\n\n\n\n<p><code>List&lt;CustomerDto> customerList = oldCustomerList.getCustomers()<\/code><br>   <code>.stream()<\/code><br>   <code>.filter(e -> e.getAmount() > 1000)<\/code><br>   <code>.forEach(mapOld2New(e, operatorId));<\/code><\/p>\n\n\n\n<p>Every element that matches the filter criteria (in this case amount larger than 1000) will be processed by a mapping method (mapOld2New) where some data conversion to type CustomerDto is done and additional the actual operatorId (that is set some lines before this stream operation is invoked) is added to the new CustomerDto. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>An interesting way to process a collection is the usage of streams. A stream provides a sequential access to the elements of the collection. Below a code snipped for a simple selection of elements of an existing collection. In this example the dataList contains just some Strings and we want to get a new list [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-398","post","type-post","status-publish","format-standard","hentry","category-java"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9W9h9-6q","jetpack-related-posts":[{"id":219,"url":"https:\/\/www.rothamel.com\/index.php\/2020\/07\/15\/docker-teil-1-tomcat-im-docker-container\/","url_meta":{"origin":398,"position":0},"title":"Container &#8211; Part 1: Tomcat im Docker-Container","author":"Rolf Rothamel","date":"2020-07-15","format":false,"excerpt":"Docker represents a pleasant possibility to create clearly defined, lightweight runtime environments (containers) and to distribute them if necessary. In the following, the creation and possible use is shown using the example of a container with Tomcat and OpenSuse.","rel":"","context":"In &quot;Allgemein&quot;","block_context":{"text":"Allgemein","link":"https:\/\/www.rothamel.com\/index.php\/category\/allgemein\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":42,"url":"https:\/\/www.rothamel.com\/index.php\/2018\/05\/22\/java-stack-vs-heap\/","url_meta":{"origin":398,"position":1},"title":"Java: Stack vs. Heap","author":"Rolf Rothamel","date":"2018-05-22","format":false,"excerpt":"Stack vs Heap 1. Stack 1.1. Struktur Der Stack stellt einen Speicherbereich dar der in Form eines LIFO Puffers (Last In \u2013 Fist Out) organisiert ist. Elemente die zuerst auf dem Stack abgelegt werden liegen unten, die zuletzt abgelegten Elemente liegen oben. Durch die Struktur des Stacks und der hierdurch\u2026","rel":"","context":"In &quot;Java&quot;","block_context":{"text":"Java","link":"https:\/\/www.rothamel.com\/index.php\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":355,"url":"https:\/\/www.rothamel.com\/index.php\/2022\/11\/13\/migration-einer-linux-vms-von-vmware-workstation-zu-hyper-v\/","url_meta":{"origin":398,"position":2},"title":"Migrating a Linux VM from VMWare Workstation to Hyper-V","author":"Rolf Rothamel","date":"2022-11-13","format":false,"excerpt":"The following is a quick guide to migrating an OpenSuse Linux VMs on VMWare Workstation to Hyper-V. Preparations Create snapshot (as a backup in case something goes wrong) Remove VMWare Tools add dracut Config: \/etc\/dracut.conf.d\/00-custom.conf and add the following line. Do not forget the spaces before and after the modules!\u2026","rel":"","context":"In &quot;Linux&quot;","block_context":{"text":"Linux","link":"https:\/\/www.rothamel.com\/index.php\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":228,"url":"https:\/\/www.rothamel.com\/index.php\/2020\/07\/17\/container-teil-2-arbeiten-mit-docker-containern\/","url_meta":{"origin":398,"position":3},"title":"Container \u2013 Part 2: Working with Docker-Containers","author":"Rolf Rothamel","date":"2020-07-17","format":false,"excerpt":"After showing the creation of an exemplary Docker container in the first part, this part of the article series now focuses on working with containers.","rel":"","context":"In &quot;Allgemein&quot;","block_context":{"text":"Allgemein","link":"https:\/\/www.rothamel.com\/index.php\/category\/allgemein\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":55,"url":"https:\/\/www.rothamel.com\/index.php\/2018\/06\/23\/kleine-proxy-kunde-reverse-proxy-vs-forward-proxy\/","url_meta":{"origin":398,"position":4},"title":"Kleine Proxy-Kunde \u2013 Reverse Proxy vs. Forward Proxy","author":"Rolf Rothamel","date":"2018-06-23","format":false,"excerpt":"Im Alltag des Internets sind Begriffe wie Proxy, Forward-Proxy, Reverse-Proxy vielfach verwendet und oftmals gleichgesetzt. Doch sind Proxies immer Proxies? Sind sie alle gleich? Mit nichten. So unterscheiden sich Forward-Proxies deutlich von Revese-Proxies in ihrem Aufbau und Zweck. Der nachfolgende Artikel setzt sich mit den beiden Proxy-Typen auseinander und beschreibt\u2026","rel":"","context":"In &quot;Allgemein&quot;","block_context":{"text":"Allgemein","link":"https:\/\/www.rothamel.com\/index.php\/category\/allgemein\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.rothamel.com\/wp-content\/uploads\/2018\/06\/prx2.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rothamel.com\/wp-content\/uploads\/2018\/06\/prx2.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rothamel.com\/wp-content\/uploads\/2018\/06\/prx2.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.rothamel.com\/wp-content\/uploads\/2018\/06\/prx2.jpg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":77,"url":"https:\/\/www.rothamel.com\/index.php\/2018\/10\/27\/liferay-development-for-beginners-part-two-creation-of-a-development-environment\/","url_meta":{"origin":398,"position":5},"title":"Liferay-Development for beginners \u2013 Part two \u2013 Creation of a development environment","author":"Rolf Rothamel","date":"2018-10-27","format":false,"excerpt":"The development for the Liferay portal is quite nice by using a local develop environment with Eclipse, Mysql and Liferay. Therefore you should download the following components: Liferay (http:\/\/sourceforge.net\/projects\/lportal\/files\/Liferay%20Portal\/) Liferay Portal bundled with Tomcat Liferay Portal sources Liferay Portal Documentation Liferay Portal SDK Eclipse Eclipse Liferay IDE (downloadable via Eclipse\u2026","rel":"","context":"In &quot;Java&quot;","block_context":{"text":"Java","link":"https:\/\/www.rothamel.com\/index.php\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/posts\/398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/comments?post=398"}],"version-history":[{"count":1,"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/posts\/398\/revisions"}],"predecessor-version":[{"id":399,"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/posts\/398\/revisions\/399"}],"wp:attachment":[{"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/media?parent=398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/categories?post=398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/tags?post=398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}