I have to develop this small program where my program can store sms messages with the senders name and date....
I have done my part on creating the sms with sendername and text :
Here are my codes :
So this is the what i need to do in my program...
1.Show all messages received from a particular sender??
I am confused how can i show the messages from a particular sender,so its like when i type this person name it shows all the messages send by him?? since i know i can only retrieve messages using the index of the arraylist.... I am stuck here... Please Help me. Thanks
DO you have to use ArrayList like what you have done here?
How about using key-value pair collection class? e.g. Use HashMap.
Store the name as key and a ArrayList as the value element. Here the ArrayList will store objects that contain all information, include message, date, etc.
well.....wat has to be done is not really complicated...i guess....
since arraylist is indexed... 1. for a particular name say 'name0' in the senderarraylist, search all the names that correspond to name0 and take that particular index and retrieve the message from the messagearraylist...
for(int i=0;i<senderlist.length;i++){ if(senderlist[i].equals(name0) System.out.println(messagelist[i];//or whatever u wanna do here }
of course if your teacher tells you to use ArrayList that's what you have to use
To store different things in an ArrayList is simple. Getting them out again is easy too, just don't forget to cast them to the correct type and get them out in the correct order (so you don't try to get a String and treat it as something else for example).
Post by:autobot
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
a bit of art, as a gift, that will fit in a stocking