โ— LIVE
OpenAI releases GPT-5 APIIndia AI startup raises $120MBitcoin ETF hits record inflowsMeta Llama 4 benchmarks leakedOpenAI releases GPT-5 APIIndia AI startup raises $120MBitcoin ETF hits record inflowsMeta Llama 4 benchmarks leaked
๐Ÿ“… Thu, 26 Mar, 2026โœˆ๏ธ Telegram
AiFeed24

AI & Tech News

๐Ÿ”
โœˆ๏ธ Follow
๐Ÿ Home๐Ÿค–AI๐Ÿ’ปTech๐Ÿš€Startupsโ‚ฟCrypto๐Ÿ”’Security๐Ÿ‡ฎ๐Ÿ‡ณIndiaโ˜๏ธCloud๐Ÿ”ฅDeals
โœˆ๏ธ News Channel๐Ÿ›’ Deals Channel
Home/Cloud & DevOps/Find the second largest string by length in a sentence using Java 8
โ˜๏ธCloud & DevOps

Find the second largest string by length in a sentence using Java 8

import java.util.Arrays; import java.util.Comparator; import java.util.Optional; public class SecondLargestString { public static void main(String[] args) { String sentence = "The quick brown fox jumps over the lazy dog"; Optional secondLargest = Arrays.stream(sentence.split("\\s+")) // 1. Split int

โšกQuick SummaryAI generating...
K

Kiran Kumar

๐Ÿ“… Mar 23, 2026ยทโฑ 2 min readยทDev.to โ†—
โœˆ๏ธ Telegram๐• TweetWhatsApp
๐Ÿ“ก

Original Source

Dev.to

https://dev.to/kiran_kumar_b/find-the-second-largest-string-by-length-in-a-sentence-using-java-8-1o7
Read Full โ†—
import java.util.Arrays;
import java.util.Comparator;
import java.util.Optional;

public class SecondLargestString {
    public static void main(String[] args) {
        String sentence = "The quick brown fox jumps over the lazy dog";

        Optional<String> secondLargest = Arrays.stream(sentence.split("\\s+")) // 1. Split into words
            .distinct() // 2. Remove duplicates (e.g., "The" and "the" would be treated as distinct here unless lowercased first)
            .sorted(Comparator.comparingInt(String::length).reversed() // 3. Sort by length in descending order
                .thenComparing(Comparator.naturalOrder())) // 4. Optional: sort alphabetically for ties in length
            .skip(1) // 5. Skip the longest string
            .findFirst(); // 6. Get the next string (the second longest)

        if (secondLargest.isPresent()) {
            System.out.println("The second largest string is: " + secondLargest.get());
        } else {
            System.out.println("Could not find the second largest string.");
        }
    }
}
Tags:#cloud#dev.to

Found this useful? Share it!

โœˆ๏ธ Telegram๐• TweetWhatsApp

Read the Full Story

Continue reading on Dev.to

Visit Dev.to โ†—

Related Stories

โ˜๏ธ
โ˜๏ธCloud & DevOps

I wanted shadcn/ui for Blazor. It didnโ€™t exist. So I built it.

about 19 hours ago

โ˜๏ธ
โ˜๏ธCloud & DevOps

Shipping Fast with AI? Youโ€™re Probably Shipping Vulnerabilities Too.

about 19 hours ago

Oops, I Vibecoded Again. Please Help Me! โ€” A CSS Refiner
โ˜๏ธCloud & DevOps

Oops, I Vibecoded Again. Please Help Me! โ€” A CSS Refiner

about 19 hours ago

๐Ÿ’ณ Dรฉtection de Fraude Bancaire & IA : Ma contribution au Notion MCP Challenge
โ˜๏ธCloud & DevOps

๐Ÿ’ณ Dรฉtection de Fraude Bancaire & IA : Ma contribution au Notion MCP Challenge

about 19 hours ago

๐Ÿ“ก Source Details

Dev.to

๐Ÿ“… Mar 23, 2026

๐Ÿ• 3 days ago

โฑ 2 min read

๐Ÿ—‚ Cloud & DevOps

Read Original โ†—

Web Hosting

๐ŸŒ Hostinger โ€” 80% Off Hosting

Start your website for โ‚น69/mo. Free domain + SSL included.

Claim Deal โ†’

๐Ÿ“ฌ AiFeed24 Daily

Top 5 AI & tech stories every morning. Join 40,000+ readers.

โœฆ 40,218 subscribers ยท No spam, ever

Cloud Hosting

โ˜๏ธ Vultr โ€” $100 Free Credit

Deploy cloud servers in 25+ locations. From $2.50/mo. No contract.

Claim $100 Credit โ†’
AiFeed24

India's AI-powered tech news hub. Daily coverage of AI, startups, crypto and emerging technology.

โœˆ๏ธ๐Ÿ›’

Topics

Artificial IntelligenceStartups & VCCryptocurrencyCybersecurityCloud & DevOpsIndia Tech

Company

About AiFeed24Write For UsContact

Daily Digest

Top 5 AI stories every morning. 40,000+ readers.

No spam, ever.

ยฉ 2026 AiFeed24 Media.Affiliate Disclosure โ€” We earn commission on qualifying purchases at no extra cost to you.
PrivacyTermsCookies