For instance, I have the following classes:
public class FooService {
private String name;
private int quantity;
public FooService(String name, int quantity) {
this.name = name;
this.quantity = quantity;
}
// getters + setters
}
and
public class FooStorage {
private FooService [] services = new FooService[10];
public void add(FooService fooService) {
}
}
I want to sort the services array in an alphabetical order according to each element's name parameter.
I know I can use a comparator in this case but it is very expensive when importing large amount of data. Can anyone help me with the insertion sort here?
EDIT: I am not allowed to use Collections. Also, do not mind about the fixed size of the array. I am allocating initially 5000 slots and then multiplying by 2 if the 5000th slot is reached in my program.