Should I use StringBuffer?
I need to make a method that takes a DNA sequence and returns it's complement.
Complementary sequence means:
1. replace every 'T' in source sequence with 'A'
2. replace every 'A' in source sequence with 'T'
3. replace every 'G' in source sequence with 'C'
4. replace every 'C' in source sequence with 'G'
5. reverse the resulting sequence
My method looks like this and works with my test strings :
I've overheard my teacher mentioning StringBuffer to other students, but I didn't have time to ask him about it.
public String getComplement(String sequence)
for (int i = sequence.length() - 1 ; i >= 0; i--)
complement += 't';
complement += 'a';
complement += 'c';
complement += 'g';
Is there any reason why I should use StringBuffer in this case?