I am currently working on a project where I need to check an arraylist for a certain string and if that condition is met, replace it with the new string. I will only show the relevant code but basically what happened before is a long string is read in, split into groups of three, then those strings populate an array. I need to find and replace those values in the array, and then print them out. Here is the method that populates the arraylist:
private static ArrayList<String> splitText(String text)
{
ArrayList<String> DNAsplit = new ArrayList<String>();
for (int i = 0; i < text.length(); i += 3)
{
DNAsplit.add(text.substring(i, Math.min(i + 3, text.length())));
}
return DNAsplit;
}
How would I search this arraylist for multiple strings (Here's an example aminoAcids = aminoAcids.replaceAll ("TAT", "Y");) and then print the new values out.
Any help is greatly appreciated.
splitTextmethod is unnecessarily complicated. Just usefor (int i = 0; i < text.length(); i += 3) { DNAsplit.add(text.substring(i, Math.min(i + 3, text.length()))); }.