I am creating a short piece of code where I need to get an item from a list and compare it to a value.
Despite importing java.util.List and writing the correct method call, it still claims it 'cannot find symbol - method getItem(int)'
import java.util.*;
import java.util.List;
public static int duplicateCharacters(String input) {
boolean number = false;
int highest = 0;
int secondHighest = 0;
if(input.length()<=1){
return -1;
}
int[] newList = new int[] {0,1,2,3,4,5,6,7,8,9};
for(int i=0; i<input.length(); i++){
number = false;
int currentValue = input.charAt(i);
for(int q=0; q<newList.length; q++){
if(newList.getItem(q) == currentValue){
number = true;
}
}
if(number == true){
if(currentValue>highest){
secondHighest = highest;
highest = currentValue;
}
}
}
return secondHighest;
}
In the Java doc, it states:
getItem
public String getItem(int index)Gets the item associated with the specified index.
Parameters:
index - the position of the itemReturns:
an item that is associated with the specified indexSee Also:
getItemCount()