I am working on my java application and i am concerned about performance speed especially because i have a lot of data structures like List, Map and so on.
I know that complexity of add(Object obj) method of LinkedList is O(1) (the main reason to use LinkedList) and the complexity of get(int index) method of ArrayList is O(1) (the main reason to use ArrayList).
I found the article below on internet :
Try to follow these rules while optimizing ArrayList performance of your code:
Add elements to the end of the list
Remove elements from the end too
Avoid contains, indexOf and remove(Object) methods
Even more avoid removeAll and retainAll methods
Use subList(int, int).clear() idiom to quickly clean a part of the list
Now what i need to know is what does it mean add elements to the end of the list because as far as i am concerned if we do not use index as parameter of the add method so in other words if we use add(Object obj) method then elements are always added to the end.
I have those two methods below and i am wondering if the performance of those methods when we will have 1000 files will be desirable or not . If not is there any way how to improve the performance
I have used profiler like jvm to measure speed performance but i am still not sure if this is the best performance i can achieve or not
public List<int[][]> AllSharesForFiles (int n , int k,List<File> file) {
sharesHolder = new LinkedList<int[][]>();
try{
for(int i=0;i<file.size();i++) {
byte[]secret = f.readingTheFile(file.get(i)); // We call the method which read the file
//method which evaluate the shares of each byte of the file
shar1= s.calculateThresholdScheme(secret, n,k,new RndGeneratorAllAlgorithm(new RandomGeneratorSHA1()),two);
sharesHolder.add(shar1);
}
} catch (IOException e) {
e.printStackTrace();
}
return sharesHolder;
}
/*Look for the possibilities to return a 2D array instead of one dimensional array
*
*/
public List<int[][]> AllSharesForEachFile (int n , int k,List<int [] []> f) {
sharesHolder1 = new LinkedList<int[][]>();
int s=f.size();
int l=f.get(1)[0].length;
for (int i = 0; i < n; i++) {
someValue=new int[s][l];
for(int j=0;j<f.size(); j++){
someValue[j]=f.get(j)[i];
}
sharesHolder1.add(someValue);
}
return sharesHolder1;
}