I have this method that receives a string that contains an integer at the end, i've tried to extract the characters and the integer this way:
public void findCardPosition(String cardLocation,ImageView cardImage){
String cardName = null;
String cardType = cardLocation.replaceAll("[^a-z]","");
String cardPosition = cardLocation.replaceAll("[^0-9]", "");
int position = Integer.parseInt(cardPosition)-1;
if(cardType=="territory"){
cardName=GameBoard.getTerritoryTower().placeTowerTerritories().get(position).getName();
}
if(cardLocation=="territory1"){
cardName=GameBoard.getTerritoryTower().placeTowerTerritories().get(position).getName();
}
if(cardName!=null){
this.findCardImage(cardName,cardImage);
}
}
In theory both IF should work but the first one doesn't which means that when i apply String cardType = cardLocation.replaceAll("[^a-z]","");
to the string "territory1"
it doesn't return the string "territory".
The string cardPosition
works, so i don't understand why the stringcardType
doesn't.