2

now a days i am working on blackberry within that i parse some JSON Array into String and from that i convert it into Hashtable like this

this is my JSON string

[ 
  { 
        "StdID":"A1",
  "RollNo":"23",
 "Class":"First"

}, 
{ 
        "StdID":"A2",
  "RollNo":"13",
 "Class":"First"

}, 
{ 
        "StdID":"A3",
  "RollNo":"53",
 "Class":"Second"

}, 
{ 
        "StdID":"A4",
  "RollNo":"33",
 "Class":"Third"

}, 

]

and i parse this into hashtable as

Hashtable t1=new Hashtable();
t1.put("StdID","A1");
t1.put("RollNo","23");
t1.put("Class","First");
Hashtable t2=new Hashtable();
t2.put("StdID","A2");
t2.put("RollNo","13");
t2.put("Class","First");
Hashtable t3=new Hashtable();
t3.put("StdID","A3");
t3.put("RollNo","53");
t3.put("Class","Second");
Hashtable t4=new Hashtable();
t4.put("StdID","A4");
t4.put("RollNo","33");
t4.put("Class","Third");

Hashtable main=new Hashtable ();

main.put(new Integer(1), t1);
main.put(new Integer(2), t2);
main.put(new Integer(3), t3);
main.put(new Integer(4), t4);

So can i/ how can i retrieve the value as

select students which have First class

so any one can help me? is this possible by LINQ ?

Nilesh Nikumbh
  • 302
  • 3
  • 15

4 Answers4

4

No. LINQ is part of .NET, not Java.

See also

Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
1

Uhm... yes! But you need this library for Java LINQ stuff: //github.com/nicholas22/jpropel-light

How to do it:

import java.util.Hashtable;
import lombok.ExtensionMethod;
import propel.core.utils.Linq;
import java.util.List;
import lombok.Function;

@ExtensionMethod({Linq.class})
public class Main
{

  public static void main(String[] args)
  {
    Hashtable t1=new Hashtable();
    t1.put("StdID","A1");
    t1.put("RollNo","23");
    t1.put("Class","First");
    Hashtable t2=new Hashtable();
    t2.put("StdID","A2");
    t2.put("RollNo","13");
    t2.put("Class","First");
    Hashtable t3=new Hashtable();
    t3.put("StdID","A3");
    t3.put("RollNo","53");
    t3.put("Class","Second");
    Hashtable t4=new Hashtable();
    t4.put("StdID","A4");
    t4.put("RollNo","33");
    t4.put("Class","Third");

    Hashtable main = new Hashtable();
    main.put(new Integer(1), t1);
    main.put(new Integer(2), t2);
    main.put(new Integer(3), t3);
    main.put(new Integer(4), t4);

    List<Hashtable> result= main.values().where(classEquals("First")).toList();
    for(Hashtable ht : result)
      System.out.println(ht.get("StdID"));
  }


  @Function
  private static Boolean classEquals(Hashtable table, String _class) {
    return table.get("Class") != null && table.get("Class").equals(_class);
  }
}
NT_
  • 2,660
  • 23
  • 25
0

No linq is for .NET 3.5 or greater not for JAVA

anishMarokey
  • 11,279
  • 2
  • 34
  • 47
0

As all are saying there is no LINQ for Java as this is only .NET technology.

But you can use APIs which offer similar functionality, e.g. quaere

BTW. someonw else also asked a similar question, please check this out.

Community
  • 1
  • 1
Boro
  • 7,913
  • 4
  • 43
  • 85