<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Raghunath on Medium]]></title>
        <description><![CDATA[Stories by Raghunath on Medium]]></description>
        <link>https://medium.com/@Raghu12?source=rss-5bf36e420664------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*MypmCFQ5PMxWUi1K</url>
            <title>Stories by Raghunath on Medium</title>
            <link>https://medium.com/@Raghu12?source=rss-5bf36e420664------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 12:43:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Raghu12/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Java Collections]]></title>
            <link>https://medium.com/@Raghu12/java-collections-2d56ea46930d?source=rss-5bf36e420664------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d56ea46930d</guid>
            <dc:creator><![CDATA[Raghunath]]></dc:creator>
            <pubDate>Mon, 31 Mar 2025 20:34:45 GMT</pubDate>
            <atom:updated>2025-03-31T20:34:45.859Z</atom:updated>
            <content:encoded><![CDATA[<p>Java Collections Framework is the foundation for storing, manipulating, and accessing data in Java. This article provides a complete and structured overview of all major collection types, interfaces, and operations with real-world Java examples, expected outputs, and detailed explanations.</p><h3>What are Java Collections?</h3><p>Java Collections is a framework that provides a set of interfaces and classes to store and manipulate groups of data efficiently. It includes Lists, Sets, Queues, Maps, and more.</p><h3>Core Interfaces:</h3><ul><li><strong>List</strong> — Ordered collection, allows duplicates (e.g., ArrayList, LinkedList)</li><li><strong>Set</strong> — Unordered, no duplicates (e.g., HashSet, LinkedHashSet, TreeSet)</li><li><strong>Queue</strong> — FIFO structure (e.g., PriorityQueue, Deque)</li><li><strong>Map</strong> — Key-value pairs (e.g., HashMap, TreeMap, LinkedHashMap)</li></ul><h3>List Interface — ArrayList</h3><p><strong>ArrayList </strong>is a resizable array implementation of the List interface. It allows random access and maintains insertion order.</p><pre>import java.util.*;<br><br>public class ListExample {<br>    public static void main(String[] args) {<br>        List&lt;String&gt; names = new ArrayList&lt;&gt;();<br>        names.add(&quot;Alice&quot;);<br>        names.add(&quot;Bob&quot;);<br>        names.add(&quot;Alice&quot;);<br><br>        System.out.println(&quot;List: &quot; + names);<br>        System.out.println(&quot;Size: &quot; + names.size());<br>        System.out.println(&quot;Contains &#39;Bob&#39;? &quot; + names.contains(&quot;Bob&quot;));<br>        names.remove(&quot;Alice&quot;);<br>        System.out.println(&quot;After removing &#39;Alice&#39;: &quot; + names);<br>        System.out.println(&quot;Is Empty? &quot; + names.isEmpty());<br>        System.out.println(&quot;To Array: &quot; + Arrays.toString(names.toArray()));<br>    }<br>}</pre><pre>Output:<br>List: [Alice, Bob, Alice]<br>Size: 3<br>Contains &#39;Bob&#39;? true<br>After removing &#39;Alice&#39;: [Bob, Alice]<br>Is Empty? false<br>To Array: [Bob, Alice]</pre><h3>Set Interface — HashSet and LinkedHashSet</h3><ul><li><strong>HashSet</strong>: Does not maintain order and doesn’t allow duplicates.</li><li><strong>LinkedHashSet</strong>: Maintains insertion order and also avoids duplicates.</li></ul><pre>import java.util.*;<br><br>public class SetExample {<br>    public static void main(String[] args) {<br>        Set&lt;Integer&gt; numbers = new HashSet&lt;&gt;();<br>        numbers.add(10);<br>        numbers.add(20);<br>        numbers.add(10);<br>        System.out.println(&quot;HashSet: &quot; + numbers);<br><br>        Set&lt;Integer&gt; linked = new LinkedHashSet&lt;&gt;();<br>        linked.add(5);<br>        linked.add(3);<br>        linked.add(5);<br>        System.out.println(&quot;LinkedHashSet: &quot; + linked);<br>    }<br>}</pre><pre>Output:<br>HashSet: [20, 10] or [10, 20]<br>LinkedHashSet: [5, 3]</pre><h3>TreeSet</h3><p><strong>TreeSet </strong>stores elements in sorted (natural) order and does not allow duplicates.</p><pre>import java.util.*;<br><br>public class TreeSetExample {<br>    public static void main(String[] args) {<br>        Set&lt;String&gt; cities = new TreeSet&lt;&gt;();<br>        cities.add(&quot;Mumbai&quot;);<br>        cities.add(&quot;Delhi&quot;);<br>        cities.add(&quot;Bangalore&quot;);<br><br>        System.out.println(&quot;Sorted TreeSet: &quot; + cities);<br>    }<br>}</pre><pre>Output:<br>Sorted TreeSet: [Bangalore, Delhi, Mumbai]</pre><h3>Queue — PriorityQueue</h3><p><strong>PriorityQueue</strong>retrieves elements based on priority (natural ordering by default).</p><pre>import java.util.*;<br><br>public class QueueExample {<br>    public static void main(String[] args) {<br>        Queue&lt;Integer&gt; pq = new PriorityQueue&lt;&gt;();<br>        pq.add(30);<br>        pq.add(10);<br>        pq.add(20);<br><br>        System.out.println(&quot;PriorityQueue: &quot; + pq);<br>        System.out.println(&quot;Poll: &quot; + pq.poll());<br>        System.out.println(&quot;After poll: &quot; + pq);<br>    }<br>}</pre><pre>PriorityQueue: [10, 30, 20] (order may vary)<br>Poll: 10<br>After poll: [20, 30]</pre><h3>Deque — ArrayDeque</h3><p><strong>Deque </strong>is a double-ended queue supporting element insertion/removal at both ends.</p><pre>import java.util.*;<br><br>public class DequeExample {<br>    public static void main(String[] args) {<br>        Deque&lt;String&gt; dq = new ArrayDeque&lt;&gt;();<br>        dq.addFirst(&quot;Front&quot;);<br>        dq.addLast(&quot;Back&quot;);<br>        System.out.println(&quot;Deque: &quot; + dq);<br>        dq.removeFirst();<br>        System.out.println(&quot;After removeFirst: &quot; + dq);<br>    }<br>}</pre><pre>Output:<br>Deque: [Front, Back]<br>After removeFirst: [Back]</pre><h3>Stack</h3><p><strong>Stack </strong>is a LIFO (last-in-first-out) collection extending Vector.</p><pre>public class StackExample {<br>    public static void main(String[] args) {<br>        Stack&lt;Integer&gt; stack = new Stack&lt;&gt;();<br>        stack.push(100);<br>        stack.push(200);<br>        System.out.println(&quot;Stack: &quot; + stack);<br>        stack.pop();<br>        System.out.println(&quot;After pop: &quot; + stack);<br>    }<br>}</pre><pre>Output:<br>Stack: [100, 200]<br>After pop: [100]</pre><h3>Map — HashMap</h3><p><strong>HashMap </strong>stores key-value pairs with no guaranteed order.</p><pre>import java.util.*;<br><br>public class HashMapExample {<br>    public static void main(String[] args) {<br>        Map&lt;Integer, String&gt; map = new HashMap&lt;&gt;();<br>        map.put(1, &quot;One&quot;);<br>        map.put(2, &quot;Two&quot;);<br>        System.out.println(&quot;Map: &quot; + map);<br>        map.remove(1);<br>        System.out.println(&quot;After remove: &quot; + map);<br>        System.out.println(&quot;Contains key 2? &quot; + map.containsKey(2));<br>    }<br>}</pre><pre>Output:<br>Map: {1=One, 2=Two}<br>After remove: {2=Two}<br>Contains key 2? true</pre><h3>Common Collection Functions</h3><pre>import java.util.*;<br><br>public class CollectionFunctions {<br>    public static void main(String[] args) {<br>        List&lt;String&gt; list = new ArrayList&lt;&gt;(List.of(&quot;A&quot;, &quot;B&quot;, &quot;C&quot;));<br>        System.out.println(&quot;Original List: &quot; + list);<br><br>        System.out.println(&quot;Contains &#39;B&#39;? &quot; + list.contains(&quot;B&quot;));<br>        System.out.println(&quot;Size: &quot; + list.size());<br><br>        list.remove(&quot;B&quot;);<br>        System.out.println(&quot;After remove: &quot; + list);<br><br>        list.add(&quot;D&quot;);<br>        System.out.println(&quot;After add: &quot; + list);<br><br>        List&lt;String&gt; another = List.of(&quot;A&quot;, &quot;D&quot;, &quot;E&quot;);<br>        list.retainAll(another);<br>        System.out.println(&quot;After retainAll: &quot; + list);<br><br>        list.removeAll(List.of(&quot;D&quot;));<br>        System.out.println(&quot;After removeAll: &quot; + list);<br><br>        list.clear();<br>        System.out.println(&quot;After clear: &quot; + list);<br>        System.out.println(&quot;Is Empty: &quot; + list.isEmpty());<br><br>        list = new ArrayList&lt;&gt;(List.of(&quot;X&quot;, &quot;Y&quot;));<br>        System.out.println(&quot;To Array: &quot; + Arrays.toString(list.toArray()));<br><br>        System.out.println(&quot;Using Iterator:&quot;);<br>        Iterator&lt;String&gt; it = list.iterator();<br>        while (it.hasNext()) {<br>            System.out.println(it.next());<br>        }<br><br>        System.out.println(&quot;Using stream:&quot;);<br>        list.stream().forEach(System.out::println);<br><br>        System.out.println(&quot;Using parallelStream:&quot;);<br>        list.parallelStream().forEach(System.out::println);<br>    }<br>}</pre><p><strong>Conclusion :</strong></p><p>Java Collections Framework is a powerful and flexible toolset that helps you manage data efficiently. Whether you’re working with lists, maps, sets, or queues — understanding these core interfaces, classes, and their operations will make your code cleaner, more efficient, and production-ready.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d56ea46930d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Streams]]></title>
            <link>https://medium.com/@Raghu12/java-streams-4ad556e05b8e?source=rss-5bf36e420664------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ad556e05b8e</guid>
            <dc:creator><![CDATA[Raghunath]]></dc:creator>
            <pubDate>Sun, 30 Mar 2025 03:48:01 GMT</pubDate>
            <atom:updated>2025-03-30T03:48:01.734Z</atom:updated>
            <content:encoded><![CDATA[<p>A <strong>Stream</strong> in Java is a sequence of elements that supports <strong>aggregate operations</strong>. Unlike collections, streams don’t store data but they process data on-demand through a <strong>pipeline</strong> of operations.</p><p>Complete Java Program demonstrating stream creation, manipulation and final operations with actual output for each block.</p><pre>import java.util.*;<br>import java.util.stream.*;<br><br><br>public class Main{<br>    public static void main(String[] args) {<br><br>        // From Collection<br>        List&lt;String&gt; names = List.of(&quot;Alice&quot;, &quot;Bob&quot;, &quot;Charlie&quot;);<br>        names.stream().forEach(System.out::println);<br>        // Output:<br>        // Alice<br>        // Bob<br>        // Charlie<br><br>        // From Array<br>        String[] cities = {&quot;Paris&quot;, &quot;London&quot;, &quot;New jersy&quot;};<br>        Arrays.stream(cities).forEach(System.out::println);<br>        // Output:<br>        // Paris<br>        // London<br>        // New jersy<br><br>        // Using Stream.of()<br>        Stream.of(&quot;Java&quot;, &quot;Python&quot;, &quot;C++&quot;).forEach(System.out::println);<br>        // Output:<br>        // Java<br>        // Python<br>        // C++<br><br>        // Stream.builder()<br>        Stream&lt;String&gt; stream = Stream.&lt;String&gt;builder().add(&quot;One&quot;).add(&quot;Two&quot;).build();<br>        stream.forEach(System.out::println);<br>        // Output:<br>        // One<br>        // Two<br><br>        // Stream.iterate()<br>        Stream.iterate(0, n -&gt; n + 2).limit(5).forEach(System.out::println);<br>        // Output:<br>        // 0<br>        // 2<br>        // 4<br>        // 6<br>        // 8<br><br>        // Stream.generate()<br>        Stream.generate(() -&gt; &quot;Hello&quot;).limit(3).forEach(System.out::println);<br>        // Output:<br>        // Hello<br>        // Hello<br>        // Hello<br><br>        // filter()<br>        names = List.of(&quot;Alex&quot;, &quot;Bob&quot;, &quot;Amanda&quot;);<br>        names.stream().filter(n -&gt; n.startsWith(&quot;A&quot;)).forEach(System.out::println);<br>        // Output:<br>        // Alex<br>        // Amanda<br><br>        // map()<br>        names.stream().map(String::toUpperCase).forEach(System.out::println);<br>        // Output:<br>        // ALEX<br>        // BOB<br>        // AMANDA<br><br>        // flatMap()<br>        List&lt;List&lt;String&gt;&gt; nested = List.of(List.of(&quot;a&quot;, &quot;b&quot;), List.of(&quot;c&quot;));<br>        nested.stream().flatMap(List::stream).forEach(System.out::print);<br>        // Output:<br>        // abc<br><br>        // distinct()<br>        List&lt;Integer&gt; numbers = List.of(1, 2, 2, 3 , 4);<br>        numbers.stream().distinct().forEach(System.out::println);<br>        // Output:<br>        // 1<br>        // 2<br>        // 3<br>        // 4<br><br>        // sorted()<br>        names.stream().sorted().forEach(System.out::println);<br>        // Output:<br>        // Alex<br>        // Amanda<br>        // Bob<br><br>        // peek()<br>        names.stream().peek(System.out::println).map(String::toUpperCase).forEach(System.out::println);<br>        // Output (mixed due to peek):<br>        // Alex<br>        // ALEX<br>        // Bob<br>        // BOB<br>        // Amanda<br>        // AMANDA<br><br>        // limit() &amp; skip()<br>        Stream.of(1, 2, 3, 4, 5).limit(3).forEach(System.out::println);<br>        // Output:<br>        // 1<br>        // 2<br>        // 3<br><br>        Stream.of(10, 20, 30, 40).skip(2).forEach(System.out::println);<br>        // Output:<br>        // 30<br>        // 40<br><br>        // mapToInt()<br>        List&lt;String&gt; values = List.of(&quot;5&quot;, &quot;10&quot;);<br>        int sum = values.stream().mapToInt(Integer::parseInt).sum();<br>        System.out.println(sum);<br>        // Output:<br>        // 15<br><br>        // toArray()<br>        String[] arr = names.stream().toArray(String[]::new);<br>        System.out.println(Arrays.toString(arr));<br>        // Output:<br>        // [Alex, Bob, Amanda]<br><br>        // reduce()<br>        Optional&lt;String&gt; result = names.stream().reduce((a, b) -&gt; a + &quot;,&quot; + b);<br>        System.out.println(result.get());<br>        // Output:<br>        // Alex,Bob,Amanda<br><br>        // collect()<br>        List&lt;String&gt; collected = names.stream().collect(Collectors.toList());<br>        System.out.println(collected);<br>        // Output:<br>        // [Alex, Bob, Amanda]<br><br>        // min() &amp; max()<br>        Optional&lt;String&gt; min = names.stream().min(Comparator.comparing(String::length));<br>        Optional&lt;String&gt; max = names.stream().max(Comparator.comparing(String::length));<br>        System.out.println(min.get()); // Output: Bob<br>        System.out.println(max.get()); // Output: Amanda<br><br>        // count()<br>        long count = names.stream().count();<br>        System.out.println(count);<br>        // Output:<br>        // 3<br><br>        // anyMatch(), allMatch(), noneMatch()<br>        boolean any = names.stream().anyMatch(n -&gt; n.equals(&quot;Alex&quot;));<br>        boolean all = names.stream().allMatch(n -&gt; n.length() &gt; 2);<br>        boolean none = names.stream().noneMatch(n -&gt; n.equals(&quot;Zoe&quot;));<br>        System.out.println(any);  // true<br>        System.out.println(all);  // true<br>        System.out.println(none); // true<br><br>        // findFirst()<br>        Optional&lt;String&gt; first = names.stream().findFirst();<br>        System.out.println(first.get());<br>        // Output:<br>        // Alex<br><br>        // Grouping with groupingBy()<br>        List&lt;String&gt; fruits = List.of(&quot;apple&quot;, &quot;apricot&quot;, &quot;banana&quot;, &quot;blueberry&quot;);<br>        Map&lt;Character, List&lt;String&gt;&gt; grouped = fruits.stream()<br>                .collect(Collectors.groupingBy(f -&gt; f.charAt(0)));<br>        System.out.println(grouped);<br>        // Output:<br>        // {a=[apple, apricot], b=[banana, blueberry]}<br><br>        // Conditional Logic (if/else)<br>        names.stream().map(n -&gt; n.equals(&quot;Alex&quot;) ? &quot;Mr. Alex&quot; : n).forEach(System.out::println);<br>        // Output:<br>        // Mr. Alex<br>        // Bob<br>        // Amanda<br><br>        // Exception Handling in Streams<br>        List&lt;String&gt; data = List.of(&quot;10&quot;, &quot;20&quot;, &quot;a&quot;, &quot;30&quot;);<br>        List&lt;Integer&gt; parsed = data.stream().map(s -&gt; {<br>            try {<br>                return Integer.parseInt(s);<br>            } catch (Exception e) {<br>                return -1;<br>            }<br>        }).collect(Collectors.toList());<br>        System.out.println(parsed);<br>        // Output:<br>        // [10, 20, -1, 30]<br><br>        // Parallel vs Sequential Streams<br>        System.out.println(&quot;Sequential:&quot;);<br>        names.stream().forEach(System.out::println);<br>        // Output:<br>        // Alex<br>        // Bob<br>        // Amanda<br><br>        System.out.println(&quot;Parallel:&quot;);<br>        names.parallelStream().forEach(System.out::println);<br>        // Output (order may vary):<br>        // Amanda<br>        // Alex<br>        // Bob<br>    }<br>}</pre><p><strong>Summary</strong></p><p>Java Streams allow you to:</p><ul><li>Write concise, declarative, and functional-style code</li><li>Easily handle collections with map-filter-reduce patterns</li><li>Scale with parallel processing when needed</li></ul><p><strong>Mastering streams</strong> boosts your Java productivity and makes your code more elegant and efficient.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ad556e05b8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>