I am writing a code where i have to add a 1d array in 2d array. For example: I have a userlist array which will add data array in it
Double[][] userList = new Double[4][appName.size()];
Double[] data = new Double[appName.size()];
so user list will have something like this:
userlist={{1,2,3,4}, {2,3,4,7}, {0,0,1,2,}}
where {1,2,3,4}===> represents data array.
Problem: The problem that i am getting is that each time what data array returns just overwrite the whole thing in userlist with the new data.
for example:
if userlist={{1,2,3,4}, {2,3,4,7}} and data returns {0,0,4,5}
then my userlist becomes: {{0,0,4,5}, {0,0,4,5}, {0,0,4,5} }.
Code:
Double[][] userList = null;
userList = new Double[4][appName.size()];
String prevName = null;
Double[] data = new Double[appName.size()];
int count=0;
for(AuditInformationEntity e : auditInfoList)
{
//int count =0;
if(prevName== null || !prevName.equals(e.getDisplayName()) )
{
if(prevName!=null)
{
////====>> I think Something to be done here<========/////
userList[count++]=data;
}
//data = new ArrayList<Double>();
for(int i = 0 ; i<appName.size();i++)
data[i]=0d;
prevName = e.getDisplayName();
}
Double d = data[appName.indexOf(e.getAppName())];
if(d==null){
d=1d;
data[appName.indexOf(e.getAppName())]= d;
}
else
{
d++;
data[appName.indexOf(e.getAppName())]= d;
}
}
userList[count++]=data;
return userList;