BioJava:Cookbook:Alphabets:Cononical

How can I tell if two Symbols or Alphabets are equal?

In Biojava the same Alphabets and the same Symbols are canonical no matter how they were constructed or where they came from. This means that if two DNA alphabets (or Symbols from those alphabets) are instantiated at different times are equal via both the .equals() and == functions. Also Symbols from the PROTEIN and the PROTEIN-TERM alphabets are canonical as are Symbols from the IntegerAlphabet and the SubIntegerAlphabet.

This is even true of Alphabets and Symbols on different virtual machines (thanks to some Serialization magic) which means BioJava works across RMI.

```java import org.biojava.bio.symbol.*; import org.biojava.bio.seq.*;

public class Canonical {

 public static void main(String[] args) {

   //get the DNA alphabet two ways
   Alphabet a1 = DNATools.getDNA();
   Alphabet a2 = AlphabetManager.alphabetForName("DNA");

   //are they equal
   System.out.println("equal: "+ a1.equals(a2));
   //are they canonical
   System.out.println("canonical: "+ (a1 == a2));
 }

} ```