int toSize=toMailIds.size();
InternetAddress[] address=new InternetAddress[toSize];
address=toMailIds.toArray(address);
Here toMailIds is arraylist.
I am getting the following exception.
java.lang.ArrayStoreException
You are going to have to use a loop in this case:
int toSize=toMailIds.size();
InternetAddress[] address=new InternetAddress[toSize];
for (int i = 0; i < toSize; i++) {
address[i] = new InternetAddress(toMailIds.get(i));
}
If a list stores Strings, the toArray method will not create InternetAddress objects from them automatically.
address=toMailIds.toArray(); is enough here. But type of address array should be Object[]
Example
List<String> list=new ArrayList<>();
Object[] atr=list.toArray();
toMailIdslist does not contain elements of typeInternetAddress