Hi and I have been working on a simple problem but can't seem to find any solution and have tried browsing the net. My question is how do I append to an array. Below is the code I tried but still doesn't work.
String[] names={""};
if (charcheck1==true) {
String[] chartmp={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
for (int j=0;j<chartmp.length;j++) {
names[names.length]=chartmp[j];
}
}
if (charcheck2==true) {
String[] chartmp={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
for (int j=0;j<chartmp.length;j++) {
names[names.length]=chartmp[j];
}
}
if (charcheck3==true) {
String[] chartmp={"1","2","3","4","5","6","7","8","9","0"};
for (int j=0;j<chartmp.length;j++) {
names[names.length]=chartmp[j];
}
}
if (charcheck4==true) {
String[] chartmp={"`","~","!","@","#","$","%","^","&","*","(",")","-","_","+","=","|","\\","[","{","]","}",";",":","'","\"",",","<",".",">","?","/"," "};
for (int j=0;j<chartmp.length;j++) {
names[names.length]=chartmp[j];
}
}
According to several sites I was browsing the above code should work but for some reason doesn't and reports a java.lang.ArrayIndexOutOfBoundsException: 1
error. Does anybody know how I can append to the array and please keep it simple as I am just beginning to learn Java? Thanks.