Encode string to base64

Java 8

@Test
public void string_base64_encode_java_8() {

    String randomPhrase = "Learn. Eat. Code.";

    String encodedPhrase = java.util.Base64.getEncoder().encodeToString(
            randomPhrase.getBytes());

    assertEquals("TGVhcm4uIEVhdC4gQ29kZS4=", encodedPhrase);
}

Google Guava

@Test
public void string_base64_encode_guava () {
    
    String randomPhrase = "Learn. Eat. Code.";
    
    String encodedPhrase = BaseEncoding.base64().encode(randomPhrase.getBytes());
    
    assertEquals("TGVhcm4uIEVhdC4gQ29kZS4=", encodedPhrase);
}

Apache Commons

@Test
public void string_base64_encoding_apache () {
    
    String randomPhrase = "Learn. Eat. Code.";
    
    Base64 base64 = new Base64();
    String encodedPhrase = base64.encodeAsString(randomPhrase.getBytes());
    
    assertEquals("TGVhcm4uIEVhdC4gQ29kZS4=", encodedPhrase);
}