Save this code from infinite recursion and make it not infinite

public void drawLine(int stars) {
    for (int i = 1; i <= stars; i++) {
        System.out.print("*");
       
    }
    if(stars>0){
        System.out.println();
        drawLine(stars - 1);
    }


}
drawLine(10);
**********
*********
********
*******
******
*****
****
***
**
*

Write a insertion or selection sort program that sorts an ArrayList in decreasing order so that the largest country is at the beginning of the array (Create your own Country class with size). Use a Comparator.

public class Country {
int size;
String countryName;

    public Country(String countryName, int size){
        this.size = size;
        this.countryName = countryName; 

    }

    public int getSize(){
        return this.size;
    }


    // compare country population sizes
    public int compareCountry(Country country) {
        if (this.getSize() < country.getSize())
        {
            return 0;
        }   
        else if (this.getSize() > country.getSize()){
            return 1;
        }
        else{
            return -1;
        }
    }

    public String toString() {
        String string = "country: " + this.countryName + " Size: " + this.size;
        return string;
    }

}
public class SelectionSort {
    public static void sort(Country[] arr) {
        for (int i = 0; i < arr.length-1; i++) {
            int min_idx = i;
            for (int j = i+1; j < arr.length; j++) {
                // use compare country, only set min_idx if -1 (smaller pop)
                if (arr[j].compareCountry(arr[min_idx]) == 1)
                    min_idx = j;
            }
            // assign temp country to swap
            Country temp = arr[min_idx];
            arr[min_idx] = arr[i];
            arr[i] = temp;
        }
    }

    public static void main(String[] args) {
    
        Country[] arr = {new Country("Argentina", 2780400 ), new Country("India", 3287260), new Country("Australia", 7741220 ), new Country("Brazil", 8515770 ), new Country("US", 9525067)};
        
    
        
        SelectionSort.sort(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
     
    }

}
SelectionSort.main(null);
country: US Size: 9525067
country: Brazil Size: 8515770
country: Australia Size: 7741220
country: India Size: 3287260
country: Argentina Size: 2780400

Test if two arraylists contain the same elements in reverse order

public static void main(String []args){
    ArrayList<String> list1=new ArrayList<String>();
    list1.add("Ellie");//Adding object in arraylist    
    list1.add("Samay");    
    list1.add("Nicky");    
    System.out.println(list1); 

    ArrayList<String> list2=new ArrayList<String>();
    list2.add("Nicky");    
    list2.add("Samaya");    
    list2.add("Ellie");    
  
    System.out.println(list2); 

    if(list1.equals(list2)) {
        System.out.println("is equal");
    }
    else{
        System.out.println("not equal");
    }
    
}
main(null);
[Ellie, Samay, Nicky]
[Nicky, Samaya, Ellie]
not equal

Remove every other element from an arraylist

public static void main(String []args){
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
list.add(6);

ArrayList<Integer> remove = new ArrayList<Integer>();
int count = 2;

for (int i = 0; i < list.size(); i++) {
    if (!(i % count == 0)) {
        remove.add(list.get(i));
    }
}

list.removeAll(remove);

System.out.print(list);
}
main(null);
[1, 3, 5]