[SalesForce] Method does not exist or incorrect signature: void get(Decimal) from the type List (32:49)

I am new to Apex and cannot seem to find a solution to the error below on the last line of code. The error I get when compiling is "Method does not exist or incorrect signature: void get(Decimal) from the type List". Any help would be awesome. Thanks.

trigger LeadingCompetitor on Opportunity (before insert, before update) {

    for (Opportunity opp : Trigger.new) {
        List<Decimal> competitorPrices = new List<Decimal>();
        competitorPrices.add(opp.Competitor_1_Price__c);
        competitorPrices.add(opp.Competitor_2_Price__c);
        competitorPrices.add(opp.Competitor_3_Price__c);

        List<String> competitors = new List<String>();
        competitors.add(opp.Competitor_1__c);
        competitors.add(opp.Competitor_2__c);
        competitors.add(opp.Competitor_3__c);

        Decimal highestPrice;
        Integer highestPricePosition; 
        for (Integer i = 0; i < competitorPrices.size(); i++) {
            Decimal currentPrice = competitorPrices.get(i);
            if (highestPrice == null || currentPrice > highestPrice) {
                highestPrice = currentPrice;
                highestPricePosition = i;
            }
        }

        opp.Highest_Priced_Competitor__c = competitors.get(highestPricePosition);
        opp.Highest_Price__c = competitorPrices.get(highestPrice);
    }
}

Best Answer

You're using the wrong index variable.

    opp.Highest_Priced_Competitor__c = competitors.get(highestPricePosition);
    opp.Highest_Price__c = competitorPrices.get(highestPrice);

The second line should also be using highestPricePosition, which is an Integer- or simply assigning highestPrice directly, since you do gather that value in your loop.

Arrays are not indexed by Decimal values, which is why the method get(Decimal) does not exist.