I am working on a method where I need complete folder path like /abc/xyz/mln/ for which I am using recurring method call as below sample code:
public String getFolderDetails(String userid, Long folderId)
{
String folderName = "";
String folderPath = "";
try {
folderName = documentFilesName.getString("name");
parentFolderId= documentFilesName.getLong("parentFolderId");
if(documentFilesName.has("parentFolderId"));
{
if(parentFolderId.exist)
{
folderPath = folderPath+"/"+folderName;
getFolderDetails(userid, parentFolderId);
}
}
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
return folderPath;
}
but every time folderName and folderPath gets assigned to "" due to recurring it doesn't keep/append the folderName and everytime new value gets assigned to folderPath.
Whats the better approach I can use here? same is happening with StringBuffer/Builder it create new object always.