I have an ArrayList of an bean class consisting five fields as
Java Bean -- MyShares
- fileName
- filePath
- fileSize
- isShared
- Creator
I Want to make a ArrayList of filePath from this arraylist of bean class
I don't have vast knowledge on Java collections. So what will be the shortest logic for this.
The present logic which I have implemented is below, Now I want an optimized Logic to do so
ArrayList<Myshares> fileDetails = new ReadSDCard().getSdCardFiles();
if (!fileDetails.isEmpty()) {
for (int i = 0; i < fileDetails.size(); i++) {
CommonUtilities.filePaths.add(fileDetails.get(i).getPath());
}
}
if (!CommonUtilities.filePaths.isEmpty()) {
for (int i = 0; i < CommonUtilities.filePaths.size(); i++) {
Log.d(Integer.toString(i), CommonUtilities.filePaths.get(i));
}
}
CommonUtilities.filePaths is my static ArrayList in which I want to store the file paths
for (Myshares share : fileDetails)) instead of the index based iteration. Then you don't need to check if the list is empty.