> I need to use Collection b/c method I'm using (Email.setTo() from
> Jakarta Commons e-mail package
[quoted text clipped - 3 lines]
> but Collection has no constructors (of course, being an interface), so
> am trying w/ArrayList and Vector,
You're good so far.
> but Vector and ArrayList's add()
> method takes an Object as parameter, but I need to add a string..
Not a problem. Since a String *is* an Object, you just call
add("someemail@yahoo.fake") and everything's fine.
> am getting ArrayStoreException..
The ArrayStoreException has nothing to do with add taking a parameter of
type Object instead of String... I don't know why you're getting it...
but if you post real example code that generates the exception, it may
help.
> so instead of
> String addOne = "add@yahoo.com";
>
> did
> String addOne = new String("add@yahoo.com");
No need to do that. The two do almost the same thing, anyway... you
should always use the first form. There are only a few rare
circumstances when you'd benefit from using that particular constructor
for String... and you shouldn't worry about them at this point.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Frances - 08 Jan 2006 14:19 GMT
>>I need to use Collection b/c method I'm using (Email.setTo() from
>>Jakarta Commons e-mail package
[quoted text clipped - 29 lines]
> circumstances when you'd benefit from using that particular constructor
> for String... and you shouldn't worry about them at this point.
thank you for your help, Chris... my code:
String add = "add@yahoo.com";
String add2 = "add2@yahoo.com";
Collection addresses = new ArrayList();
addresses.add(add);
addresses.add(add2);
.......
email.setTo(addresses);
Frances
Mark Thomas - 08 Jan 2006 14:58 GMT
<snip>
> thank you for your help, Chris... my code:
>
[quoted text clipped - 5 lines]
> ........
> email.setTo(addresses);
Frances
Your problem is that the Collection that the setTo() method expects is a
Collection of javax.mail.internet.InternetAddress, not a collection of
String. The Jakarta Commons e-mail package builds onto the javax.mail
package, so you need to download that, then using:
import javax.mail.internet.InternetAddress;
replace your:
String add = "add@yahoo.com";
String add2 = "add2@yahoo.com";
with:
InternetAddress add = new InternetAddress("add@yahoo.com");
InternetAddress add2 = new InternetAddress("add2@yahoo.com");
and away you go!
Mark
Frances - 08 Jan 2006 15:28 GMT
> <snip>
>
[quoted text clipped - 29 lines]
>
> Mark
Mark, thank you so much, that worked indeed....:)
Yes I know Jakarta-Commons email works in conjunction w/JavaMail, I was
using JavaMail alone until I discovered Jakarta-Commons email..
(since you're familiar with Jakarta-Commons email, can I ask you another
question? how do I deal w/when e-mail doesn't get sent? (for ex. if I
try sending email to a non-existent adress?) I'm catching
EmailException in catch block, but if email doesn't get sent I don't get
an exception... this
} catch (EmailException e) {
e.printStackTrace();
doesn't get triggered if email doesn't get sent.. again, thank you very
much for your help.. Frances
Mark Thomas - 08 Jan 2006 16:39 GMT
<snip>
> Mark, thank you so much, that worked indeed....:)
I'm glad to be of help.
> Yes I know Jakarta-Commons email works in conjunction w/JavaMail, I was
> using JavaMail alone until I discovered Jakarta-Commons email..
[quoted text clipped - 10 lines]
> doesn't get triggered if email doesn't get sent.. again, thank you very
> much for your help.. Frances
If you're not getting an EmailException it probably means that the email
has been successfully sent, but can't be delivered for some reason. For
example, if the To address is invalid in some way, we can successfully
send the email, but it won't be delivered - it will bounce. Have you
had any bounce returns? Sorry I can't help much here.
Mark
Frances - 08 Jan 2006 20:37 GMT
> <snip>
>
[quoted text clipped - 24 lines]
>
> Mark
again thank you very much Mark.. I did set a bounce address.. just
sent email to two unexisting addresses and email did not bounce back to
me.. oh well, have to further investigate.. thanks again.. Frances
Frances - 08 Jan 2006 20:38 GMT
>> <snip>
>>
[quoted text clipped - 28 lines]
> sent email to two unexisting addresses and email did not bounce back to
> me.. oh well, have to further investigate.. thanks again.. Frances
ooops.. take that back, just got my two bounced e-mails.. took a bit.. :)
Frances
Frances - 08 Jan 2006 15:49 GMT
> <snip>
>
[quoted text clipped - 29 lines]
>
> Mark
Mark, the reason I hadn't realized this InternetAddress thing (which I
AM familiar with b/c used JavaMail alone for a bit before starting to
use Jak-Commons email) is that if I tried to send e-mail to only one
address a simple string for email add was enough..
String To = "me@yahoo.com";
email.addTo(To);
so: if you send to only one address a simple string for address will do,
but if you send to more than one address then addresses have to be type
InternetAdress instead of string....:) (??)
many thanks again... Frances
Mark Thomas - 08 Jan 2006 16:43 GMT
> Mark, the reason I hadn't realized this InternetAddress thing (which I
> AM familiar with b/c used JavaMail alone for a bit before starting to
[quoted text clipped - 8 lines]
> InternetAdress instead of string....:) (??)
> many thanks again... Frances
Yes that's right. I haven't looked, but I expect that the addTo()
method creates the InternetAddress internally. But it is a shame that
there is this inconsistency.
Mark
Ricky Clarkson - 13 Jan 2006 02:21 GMT
Chris Smith,
>> String addOne = new String("a...@yahoo.com");
> There are only a few rare
> circumstances when you'd benefit from using that particular constructor
> for String... and you shouldn't worry about them at this point
Could you explain what they are, apart from demonstrating the
difference between objects and variables (between == and equals)?
Or, of course, point to somewhere that explains it.
Cheers.
Roedy Green - 13 Jan 2006 03:34 GMT
On 12 Jan 2006 18:21:38 -0800, "Ricky Clarkson"
<ricky.clarkson@gmail.com> wrote, quoted or indirectly quoted someone
who said :
>Could you explain what they are, apart from demonstrating the
>difference between objects and variables (between == and equals)?
>
>Or, of course, point to somewhere that explains it.
see http://mindprod.com/jgloss/gotchas.html#COMPARISON

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Chris Smith - 13 Jan 2006 06:03 GMT
> Chris Smith,
>
[quoted text clipped - 6 lines]
> Could you explain what they are, apart from demonstrating the
> difference between objects and variables (between == and equals)?
Mainly, this scenario. Let's say you want to find a piece of
information in a large text file. You read the entire text file into a
String, then find the information and use substring(...) to extract it
from the orginal String. There's a problem now. The resulting String
object looks like it's just a few characters long, but it's really
pointing behind the scenes to the ENTIRE orginal String that was read
from the text file. The original String actually shares data with its
substring. That's meant as an optimization, but if you intend to
discard the original String and keep the tiny subset, it can keep a lot
of garbage in memory.
The solution is to use new String. The String constructor that takes
another String as a parameter will actually copy not just the String
object, but also the underlying char array that it points to. Now the
old really long String can be garbage collected, and you're only using a
small amount of memory for the tiny information you've extracted from
the file.
As I said, it's a little arcance, but it's there.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation