开发者

How to store this values

is there type is there to s开发者_开发技巧tore the value

     <string,string,int>

if i use Namedlist(Solr),List it can be achieved? if so how to use.

Any other way is there?

example:

   <"A",America,code>
   <"B",London,code>

I need this in java

THANKS IN ADVANCE


Why don't you create a Class compose of these datatypes.

Example:

class MyObject
{
    int code;
    String country;
    String Flag;

    // Getters and Setters goes here.
}

Now we can use this class in a List.

List<MyObject> list;


public class Triple<T1, T2, T3> {

 private T1 o1;
 private T2 o2; 
 private T3 o3;

 public Triple(T1 o1, T2 o2, T3 o3) {
  this.o1 = o1;
  this.o2 = o2;
  this.o3 = o3;
 }

 public void setO1(T1 o1) {
  this.o1 = o1;
 }
 public T1 getO1() {
  return o1;
 }
 public void setO2(T2 o2) {
  this.o2 = o2;
 }
 public T2 getO2() {
  return o2;
 }
 public void setO3(T3 o3) {
  this.o3 = o3;
 }
 public T3 getO3() {
  return o3;
 }
}

Example:

List<Triple<String, Integer, String>> list 
  = new ArrayList<Triple<String, Integer, String>>();
list.add(new Triple("tr1", 1, "Triple 1"));
list.add(new Triple("tr2", 2, "Triple 2"));
list.add(new Triple("tr3", 3, "Triple 3"));


IMHO it depends on how you will use it. For example, if you will always look for code when you have country+flag (and vice versa), it makes sence to group county+flag:

  Map<Map<String,String>,Integer> myMap...


I would write it like this:

public class App {

    public static void main(String[] args) {
        Map<String, Location> map = new HashMap<String, Location>();

        map.put("B", City.London);
    }
}

enum City implements Location {
    London(262);
    private int code;

    private City(int code) {
        this.code = code;
    }

    @Override
    public int getCode() {
        return code;
    }
}

interface Location {
     int getCode();
}

This allows to search by primary key. And makes constant like code linked to location constant. Covering interface will allow to put there different enum constants/objects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜