Click here to Skip to main content
15,886,046 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have C# code that takes values of dictionary, sorts them and turns into list (using Linq). I would like to know how to do the same thing in Java (prefer most simple way).

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Test
{
    class Test
    {
        static void Main() {
            Dictionary<string, string> wars = new Dictionary<string,string> () {
                {"WWI","1914-1918"}, {"WWII","1939-1945"}, {"Vietnam War","1955-1975"}
            };

            var query=(from item in wars orderby item.Value descending select item.Value).ToList();

            foreach (var i in query) {
                Console.WriteLine (i);
            }
        }
    }


What I have tried:

Tried to Google, but didn't found simple solution.
Posted
Updated 1-Jul-16 4:13am

I wonder what you searched for in Google, I found this first time: Collections (Java Platform SE 7 )[^].
 
Share this answer
 
Hi buddy check this useful link about linq query in java

LINQ for Java: Quaere[^]

Getting Started with Linq Queries[^]

Best Java Equivalent for LINQ (C#) | Abundant Code[^]

I hope it will help you
 
Share this answer
 
AFAIK, Java doesn't have an equivilent facility to LINQ.

That LINQ code just returns the list sorted by Value (the date range in each item). Java has it's own sort methods.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900