help: how te read multidimensional arraylist?
public ArrayList listGroupResult=new ArrayList();
CachedRowSet crs ="xxxxxxxxxxxxxxxx"
while (crs.next()){
listGroupResult.add(new ArrayList());
intGroupId=crs.getInt("game_group_id");
((ArrayList)listGroupResult.get(i)).add(intGroupId);
intResult=Roulette();
((ArrayList)listGroupResult.get(i)).add(intResult);
i=i+1;
}
above is the multidimensional array that i create. but i fail to retrieve back the value in the arraylist. can anyone please help me?
publicint GetGroupResult(int GroupId){
int intResult=-1;
for(int i=0;i<server.listGroupResult.size();i++){
if(Integer.parseInt(server.listGroupResult.get(i).toString())==GroupId){
intResult=Integer.parseInt(server.listGroupResult.get(i).toString());
}
}
return intResult;
}
above is the code i write to read the arraylist, it show error
java.lang.NumberFormatException: For input string: "[1, 17]">
[1656 byte] By [
gracebabya] at [2007-11-27 11:16:28]

Your overall design appears faulty to my eye in that it is easy to make a mistake doing it this way. Surely there is a better way to organize your data. That being said, let's look at your second group of code.
I believe that listGroupResult is an arraylist of arraylists, correct? If so, then:
server.listGroupResult.get(i) is an arraylist.
If so, then server.listGroupResult.get(i).toString() is meaningless. You need to go further into the depths of the list.
But don't even do this. Scrap this design and start from scratch. Consider using classes to hold arraylists or something on that sort.
thanks for relply/
can u tell me how to manage it in better way? any example? the arraylist actually i am use to keep id and result.
correction:
But don't even do this. Scrap this design and start from scratch. Consider using a single ArrayList to hold objects of the same class.
if use single arraylist means i need 2 arraylist to hold my data?
actually the data is need to modify from time to time?
Something like this:
public class GrpInfo
{
private int groupID;
private int intResult;
public GrpInfo(int groupID, int intResult)
{
this.groupID = groupID;
this.intResult = intResult;
}
public int getGroupID()
{
return groupID;
}
public int getIntResult()
{
return intResult;
}
}
import java.util.ArrayList;
import java.util.List;
import javax.sql.rowset.CachedRowSet;
public class GrpInfoTester
{
private List<GrpInfo> grpInfoList = new ArrayList<GrpInfo>();
private CachedRowSet crs = "xxxxxxxxxxxxx";
public void getCrs()
{
while (crs.next())
{
int grpID = crs.getInt("game_group_id");
int result = Roulette();
grpInfoList.add(new GrpInfo(grpID, result));
}
}
public int getGroupResult(int grpID)
{
int intResult = -1;
for (int i = 0; i < grpInfoList.size(); i++)
{
if (grpInfoList.get(i).getGroupID() == grpID)
{
intResult = grpInfoList.get(i).getIntResult(); // ***** error corrected!
}
}
return intResult;
}
private int Roulette()
{
// what ever this is supposed to do?
return 0;
}
}
Message was edited by:
petes1234
> if use single arraylist means i need 2 arraylist to
> hold my data?
> actually the data is need to modify from time to time?
No, you can modify objects easily and safely. In fact I can almost guarantee you that my way is safer than yours. To modify my objects, add setters to the GrpInfo class.
Also, tell me which of our code is easier to understand and maintain? Yours or mine?
thanks for your code. i am new in java. can u tell me how to add setter in class?
Here's my GrpInfo class with setters:
public class GrpInfo
{
private int groupID;
private int intResult;
public GrpInfo(int groupID, int intResult)
{
this.groupID = groupID;
this.intResult = intResult;
}
public int getGroupID()
{
return groupID;
}
public int getIntResult()
{
return intResult;
}
public void setGroupID(int groupID)
{
this.groupID = groupID;
}
public void setIntResult(int intResult)
{
this.intResult = intResult;
}
}
Once you start using them, they will be second nature to you. Since you don't know java well, I wonder if you are trying to do things that at present are a bit beyond your level of sophistication. You really need to grasp the basics before doing this stuff, don't you think?
thanks. actually i have done the setter. ^^
giv you Duke Stars for helping me up. ^^
thnx again, good luck w/ your project. enough duke's stars and I'll be able to redeem them for coffee and doughnuts (or so I've been told).
*********** Please note the error in my GrpInfoTester code that has been corrected. ***********