Fetching information from map
Hello,
I want to do operations on data contained in a MAP. For now I associate a key (which is the name of a person) several intervals containing two dates (that I created for a class with Interval Start and Finish I add in an ArrayList before putting in the map. I would now like to identify the start date and end date way to do operations on the latter (subtraction then cancels out dates in the interval to count the number of days). Any help on this will be highly appreciated.
Re: Fetching information from map
Hello,
I do not know what you are exactly asking about, but I know that to browse the list of values must be this, this can help you.
Code:
/ / To browse the values
for (Iterator i = map.values().iterator() I.hasNext() ; ){
System.out.System.out.println( i.next() );
I think you have not explained your code very well. Please explain in more details what exactly do you want to do.
Re: Fetching information from map
Hello,
You can try the following code, if it suits you well and good.
Code:
for (Iterator i = map.values().iterator() I.hasNext() ; ) {
/ / System.out.println (i.next ());
List inv = (List)i.next();
for (Iterator j = inv.iterator() J.hasNext() ; ) {
Interval intl = j.next();
Start = st intl.Getst();
Finish = intl end.getFinish();
}
}
Re: Fetching information from map
Hello,
I need the dates identified in the key function is the first element of comparison forth has continued. I tried a 'For' embracing what you told me but it did not. I also tried this way but I have not managed to do better than that, i.e do not split dates.
Code:
for(Iterator it = map.entrySet().iterator(); It.hasNext();) {
Map.Entry e = (Entry) it.next();
Object k = e.getKey();
Object v = e.getValue();
System.out.System.out.println("nm:"K + +"Xqsq"+ v);
}
Any help on this will highly appreciated. Thanks in advance.
Re: Fetching information from map
Hello,
I have a code with me, you can try it, here it is
Code:
void tmap(){
/ / ierator on the map
Iterator <Map.Entry<Couple <String> List>> i = map.entrySet().ierator();
while (i.hasNext()){
Map.Entry<Couple <String> List> peer = i.next();
/ / get the key
Couple couple = peers.getKey();
/ / displays the full name associated wih the pair
System.out.print(couple.getName() + " " + Couple.getpara() + " : ");
/ / get value
List list = <String> peers.getValue();
/ / display each iem in the list
for(int i =0; I <list.size(); I + +)
System.out.print(list.get(i) + " ");
System.out.System.out.println("");
}
}
Re: Fetching information from map
Hello,
Thanks for your replies guys, I have made some of the changes in my code. So, here is my modified and updated code. Have a look at it and if you find any mistakes, then please correct me.
Code:
Public void tmap(){
for(Iterator i = map.entrySet().ierator(); It.hasNext();) {
Entry e = (Entry) i.next();
Object k = e.getKey();
Object v = e.getValue();
for (Iterator j = ((AbstractList <GregorianCalendar>) v).ierator() J.hasNext() ; ) {
Interval interval = (Interval) j.next();
String interval = deb.Getstart();
String interval = finn.getFinish();
String day = interval.getJour();
if(deb! =null Finn & &! =null){
System.out.System.out.println("nm:"K + +"- Start"+ + deb"End"+ finn);}
else {
System.out.System.out.println("nm:"k + +"- Day of absence"+ Day) ;
}
}
}
}