ArrayList to String/outOfBounds
Hiya,
I am trying to create a single String out of an array list.
I am building up the code, but does anyone know why I get a arrayOutOfBounds for this
Code Java:
protected ArrayList<Dice> allRounds = new ArrayList<Dice>();
protected String[] roundInfo = new String[allRounds.size()];
....................................................................................................
public void newFin(Dice addRound) {
allRounds.add(addRound);
}
public String[] getInfoForAll) {
for (int i = 0; i<allRounds.size(); i++) {
roundInfo[i] = getInfo(allRounds.get(i));
}
return roundInfo;
}
or does anyone know how to create a single String out of an array of Strings?
Thanks,
Re: ArrayList to String/outOfBounds
why do not use roundInfo.length instead of allRound.size()?? to create a single String out of an array of Strings just do astring+=array[i];
Re: ArrayList to String/outOfBounds
because it is in arrayList not an array? so array.length is wrong?
Re: ArrayList to String/outOfBounds
You are going to need to post something we can compile.
Take a look at this and see if it will help you:
Code Java:
import java.util.ArrayList;
public class ArrayListString {
/**
* JavaProgrammingForums.com
*/
public static void main(String[] args) {
ArrayList<String> al = new ArrayList<String>();
// Fill ArrayList (index, String)
al.add(0, "Java");
al.add(1, "Programming");
al.add(2, "Forums");
al.add(3, ".com");
// Convert ArrayList to Object array
Object[] elements = al.toArray();
String myString = "";
// Print Object content
for (int a = 0; a < elements.length; a++) {
//System.out.println(elements[a]);
myString = myString + elements[a];
}
// New complete String
System.out.println(myString);
}
}
Re: ArrayList to String/outOfBounds