I'm trying to read in a list of strings of characters A, C, G,and T (ignoring case), and to ignore the rest of the string if it contains any other character.
how do I code this? do I use indexOf?
V new to Java yes. Not trolling just need help quickly.
Alright, so you need to filter out from the list those strings which have characters other than TGAC? What you do to see if a string is 'good' is to iterate over the indexes of its characters, and see with charAt if one isn't equal any of those characters. In other words
boolean isGood(String str) {
for (int i = 0; i < str.length(); i++) {
if ("CGAT".indexOf(str.charAt(i)) < 0) { // look up the return values of indexOf
return false;
}
}
return true;
}
That just tells you if the string is acceptable, the rest is up to you.