Although I know usage of Java Vectors is discouraged as its deprecated, I am stuck with a legacy code where in I don't have the luxury to modify it.
I am getting an OutOfMemoryError while trying to addElement to the Vector. Following below is my code snippet. Please let me know if I can improve the below code.
/*objOut is the Vector Object.
idx is incoming integer argument.
Val is some Object
*/
int sz = objOut.size();
if (idx == sz) {
objOut.addElement(val);
} else if (idx > sz) {
for (int i = (idx-sz); i>0; i--) {
objOut.addElement(null); // Code through OutOfMemory in this line
}
objOut.addElement(val);
} else {
objOut.setElementAt(val, idx);
}