how to store an array of <string, string>
Hi,
I want to store an array of <string1, string2> in a container. string1 is not distinct and will have the same value.
i want to access the individual elements of the array for further processing.
what container can i use?
your help and pointers are appreciated
regards
[311 byte] By [
chabhia] at [2007-11-27 10:42:34]

Have a look at an implementation of the java.util.Map interface.
Hey, as u do want to access all the data which might be dupes as usaid, u could use any of the containers, but not MAP, as they do not allow duplicate entries....
cheersss.....................
> Hey, as u do want to access all the data which might
> be dupes as usaid, u could use any of the containers,
> but not MAP, as they do not allow duplicate
> entries....
>
> cheersss.....................
Wong: a Map allows for duplicate values. The OP said that one of his attributes was unique (key) and one wasn't (value).
> > Hey, as u do want to access all the data which
> might
> > be dupes as usaid, u could use any of the
> containers,
> > but not MAP, as they do not allow duplicate
> > entries....
> >
> > cheersss.....................
>
> Wong: a Map allows for duplicate values. The OP said
> that one of his attributes was unique (key) and one
> wasn't (value).
He did? It looks like string1 is not unique but I do not see any indication that string2 is unique.
jbisha at 2007-7-28 19:19:09 >

> ...
> He did? It looks like string1 is not unique but I do
> not see any indication that string2 is unique.
Yes, you are right. By explicitly stating that string1 is not unique I assumed that string2 was.
I just wanted to make sure that the OP understood that he can store the same values in his Map as long as the key is unique. If both are not unique, then a Map is out of the question (just explaining it for the OP of course).
Perhaps I reacted a bit blunt towards the other poster which is because of his/her use of those nasty sms-abbreviations and overuse of punctuation.
sorry guys if i was not crystal clear... both the arguments can be duplicate
but my understanding about these assosciative containers was first argument is key and the second is value...thats why did not bother to explicitly mention about the second argument...
any case...thanks for all the hints...will check on them
actually had implemented it using hashmap...but cant find a iterator which can help access the key and the value at the same time..
thanks
Message was edited by:
chabhi
> sorry guys if i was not crystal clear...
>
> but my understanding about these assosciative
> containers was first argument is key and the second
> is value...thats why did not bother to explicitly
> mention about the second argument...
>
> any case...thanks for all the hints...will check on
> them
>
> actually had implemented it using hashmap...but cant
> find a iterator which can help access the key and the
> value at the same time..
>
> thanks
If you want to (directly) access elements based on their key AND on their value, then you cannot use a Map.
> > ...
> > He did? It looks like string1 is not unique but I
> do
> > not see any indication that string2 is unique.
>
> Yes, you are right. By explicitly stating that
> string1 is not unique I assumed that string2 was.
> I just wanted to make sure that the OP understood
> that he can store the same values in his Map as long
> as the key is unique. If both are not unique, then a
> Map is out of the question (just explaining it for
> the OP of course).
> Perhaps I reacted a bit blunt towards the other
> poster which is because of his/her use of those nasty
> sms-abbreviations and overuse of punctuation.
........got.......it......l8r.......
jbisha at 2007-7-28 19:19:09 >

guys i am still not able to resolve this issue...
trying to use a hashmap but cant find any function which helps me to get the key and the value together in the same iteration...
I don't think you want any type of Map (HashMap included), since both your string1 and string2 are allowed to be duplicates.
Why not just create your own custom class that can contain two Objects, (i.e. Pair):
public Pair (Object o1, object o2);
public Object getFirst();
public Object getSecond();
Then just create declar a variable with the type "Set<Pair>".
thanks for your reply..
got it working in this manner
for (Map.Entry<String, String> entry: messageMap.entrySet())
{
getDbusSession().publish(entry.getKey(), entry.getValue());
}
> I don't think you want any type of Map (HashMap
> included), since both your string1 and string2 are
> allowed to be duplicates.
>
> Why not just create your own custom class that can
> contain two Objects, (i.e. Pair):
> public Pair (Object o1, object o2);
> public Object getFirst();
> public Object getSecond();
>
> Then just create declar a variable with the type
> "Set<Pair>".
you were right...i could have saved some time by checking your response..
thanks a lot for your help