public void sortDatabase(){
for(int j=0;j<productDatabase.size()-1;j++){
for(int i =0;i<productDatabase.size()-j-1;i++){
if(compareTo(i)){
Collections.swap(productDatabase,i,i++ ); //Με την Χρήση της Collections βιβλιοθήκης κάνω SWAP! Πρέπει να βάλω την βιβλιοθήκη όμως!
}
}
}
}
public boolean compareTo(int index){
if(productDatabase.get(index).getPrice() > productDatabase.get(index++).getPrice()){
return true;
}
else
return false;
}
Last time i posted my answer in a very bad way. Sorry for my english that really suck , but here is my problem. I 've declared an ArrayList < class of Product > productDatabase . Product class has some fields in it. The main problem is that i cannot sort my productDatabase elements .
I use Collections.swap() but can i use that method even if my ArrayList consists of elements that are another object ?
Also i want you to take a look at my compareTo method that i wrote which is boolean and returns me a value to know if swap of elements is needed.
Thanks in advance ... and feeling sorry for my latest first bad post.