Convert Figma logo to code with AI

vdurmont logoemoji-java

The missing emoji library for Java :heart:

2,612
513
2,612
82

Top Related Projects

A markdown version emoji cheat sheet

2,363

Find relevant emoji from text on the command-line :open_mouth: :sparkles: :raised_hands: :horse: :boom: :see_no_evil:

Quick Overview

Emoji-java is a lightweight Java library that provides easy-to-use methods for working with emojis. It allows developers to parse, search, and manipulate emoji characters in their Java applications, supporting both Unicode emoji representations and shortcodes.

Pros

  • Simple and intuitive API for handling emojis
  • Supports both Unicode emoji characters and shortcodes
  • Regularly updated with new emoji releases
  • Small footprint with minimal dependencies

Cons

  • Limited to Java applications
  • May not support some platform-specific emoji variants
  • Requires manual updates to stay current with new emoji releases
  • Limited customization options for emoji rendering

Code Examples

  1. Parse emoji from Unicode or shortcode:
Emoji emoji = EmojiManager.getForAlias("smile");
System.out.println(emoji.getUnicode()); // 😄

emoji = EmojiManager.getByUnicode("🍕");
System.out.println(emoji.getAliases()); // [pizza]
  1. Convert text with shortcodes to Unicode emojis:
String text = "I :heart: emoji!";
String result = EmojiParser.parseToUnicode(text);
System.out.println(result); // I ❤️ emoji!
  1. Remove all emojis from a string:
String text = "An 😀awesome 😃string with a few 😉emojis!";
String result = EmojiParser.removeAllEmojis(text);
System.out.println(result); // An awesome string with a few emojis!

Getting Started

To use emoji-java in your project, add the following dependency to your Maven pom.xml file:

<dependency>
  <groupId>com.vdurmont</groupId>
  <artifactId>emoji-java</artifactId>
  <version>5.1.1</version>
</dependency>

For Gradle, add this to your build.gradle file:

implementation 'com.vdurmont:emoji-java:5.1.1'

Then, you can start using the library in your Java code:

import com.vdurmont.emoji.EmojiParser;

public class EmojiExample {
    public static void main(String[] args) {
        String text = "I :heart: emoji!";
        String result = EmojiParser.parseToUnicode(text);
        System.out.println(result); // I ❤️ emoji!
    }
}

Competitor Comparisons

A markdown version emoji cheat sheet

Pros of emoji-cheat-sheet

  • Comprehensive and up-to-date emoji reference
  • Markdown-friendly format for easy integration
  • Includes categories and aliases for better organization

Cons of emoji-cheat-sheet

  • Not a Java library, requires manual implementation
  • Lacks built-in parsing and conversion functions
  • May require additional processing for use in Java applications

Code Comparison

emoji-java:

Emoji emoji = EmojiManager.getForAlias("smile");
String unicode = emoji.getUnicode();
String htmlCode = emoji.getHtmlDecimal();

emoji-cheat-sheet:

| :smile: | `:smile:` | 😄 |

Summary

emoji-cheat-sheet is a comprehensive reference for emojis, providing a well-organized list with categories and aliases. It's ideal for documentation and quick lookups but requires additional implementation for use in Java applications. emoji-java, on the other hand, is a Java library that offers built-in parsing and conversion functions, making it more suitable for direct integration into Java projects. While emoji-cheat-sheet provides a broader range of emojis and better organization, emoji-java offers more practical functionality for Java developers.

2,363

Find relevant emoji from text on the command-line :open_mouth: :sparkles: :raised_hands: :horse: :boom: :see_no_evil:

Pros of emoj

  • Command-line interface for easy emoji search and insertion
  • Supports fuzzy search for finding emojis by description
  • Lightweight and focused solely on emoji search functionality

Cons of emoj

  • Limited to command-line usage, not suitable for integration into Java applications
  • Lacks comprehensive emoji data and manipulation features
  • No support for custom emoji or extended Unicode characters

Code comparison

emoj:

const emoj = require('emoj');

emoj('heart').then(emojis => {
  console.log(emojis);
});

emoji-java:

import com.vdurmont.emoji.EmojiManager;

String emoji = EmojiManager.getForAlias("heart").getUnicode();
System.out.println(emoji);

Key differences

  • emoji-java is a Java library, while emoj is a Node.js package
  • emoji-java provides more comprehensive emoji data and manipulation
  • emoj focuses on command-line search and insertion
  • emoji-java offers better integration for Java applications
  • emoj has a simpler API for basic emoji lookup

Use cases

emoji-java:

  • Java applications requiring emoji support
  • Projects needing detailed emoji information and manipulation

emoj:

  • Command-line tools for quick emoji lookup
  • Scripts or applications requiring simple emoji search functionality

Both projects serve different purposes and target different programming environments, making direct comparison challenging in some aspects.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

emoji-java

Build Status Coverage Status License Info

The missing emoji library for java.

emoji-java is a lightweight java library that helps you use Emojis in your java applications.

How to get it?

Via Maven:
<dependency>
  <groupId>com.vdurmont</groupId>
  <artifactId>emoji-java</artifactId>
  <version>5.1.1</version>
</dependency>

You can also download the project, build it with mvn clean install and add the generated jar to your buildpath.

Via Gradle:
compile 'com.vdurmont:emoji-java:5.1.1'
Via Direct Download:

How to use it?

EmojiManager

The EmojiManager provides several static methods to search through the emojis database:

  • getForTag returns all the emojis for a given tag
  • getForAlias returns the emoji for an alias
  • getAll returns all the emojis
  • isEmoji checks if a string is an emoji
  • containsEmoji checks if a string contains any emoji

You can also query the metadata:

  • getAllTags returns the available tags

Or get everything:

  • getAll returns all the emojis

Emoji model

An Emoji is a POJO (plain old java object), which provides the following methods:

  • getUnicode returns the unicode representation of the emoji
  • getUnicode(Fitzpatrick) returns the unicode representation of the emoji with the provided Fitzpatrick modifier. If the emoji doesn't support the Fitzpatrick modifiers, this method will throw an UnsupportedOperationException. If the provided Fitzpatrick is null, this method will return the unicode of the emoji.
  • getDescription returns the (optional) description of the emoji
  • getAliases returns a list of aliases for this emoji
  • getTags returns a list of tags for this emoji
  • getHtmlDecimal returns an html decimal representation of the emoji
  • getHtmlHexadecimal returns an html decimal representation of the emoji
  • supportsFitzpatrick returns true if the emoji supports the Fitzpatrick modifiers, else false

Fitzpatrick modifiers

Some emojis now support the use of Fitzpatrick modifiers that gives the choice between 5 shades of skin tones:

ModifierType
🏻type_1_2
🏼type_3
🏽type_4
🏾type_5
🏿type_6

We defined the format of the aliases including a Fitzpatrick modifier as:

:ALIAS|TYPE:

A few examples:

:boy|type_1_2:
:swimmer|type_4:
:santa|type_6:

EmojiParser

To unicode

To replace all the aliases and the html representations found in a string by their unicode, use EmojiParser#parseToUnicode(String).

For example:

String str = "An :grinning:awesome :smiley:string &#128516;with a few :wink:emojis!";
String result = EmojiParser.parseToUnicode(str);
System.out.println(result);
// Prints:
// "An 😀awesome 😃string 😄with a few 😉emojis!"

To aliases

To replace all the emoji's unicodes found in a string by their aliases, use EmojiParser#parseToAliases(String).

For example:

String str = "An 😀awesome 😃string with a few 😉emojis!";
String result = EmojiParser.parseToAliases(str);
System.out.println(result);
// Prints:
// "An :grinning:awesome :smiley:string with a few :wink:emojis!"

By default, the aliases will parse and include any Fitzpatrick modifier that would be provided. If you want to remove or ignore the Fitzpatrick modifiers, use EmojiParser#parseToAliases(String, FitzpatrickAction). Examples:

String str = "Here is a boy: \uD83D\uDC66\uD83C\uDFFF!";
System.out.println(EmojiParser.parseToAliases(str));
System.out.println(EmojiParser.parseToAliases(str, FitzpatrickAction.PARSE));
// Prints twice: "Here is a boy: :boy|type_6:!"
System.out.println(EmojiParser.parseToAliases(str, FitzpatrickAction.REMOVE));
// Prints: "Here is a boy: :boy:!"
System.out.println(EmojiParser.parseToAliases(str, FitzpatrickAction.IGNORE));
// Prints: "Here is a boy: :boy:🏿!"

To html

To replace all the emoji's unicodes found in a string by their html representation, use EmojiParser#parseToHtmlDecimal(String) or EmojiParser#parseToHtmlHexadecimal(String).

For example:

String str = "An 😀awesome 😃string with a few 😉emojis!";

String resultDecimal = EmojiParser.parseToHtmlDecimal(str);
System.out.println(resultDecimal);
// Prints:
// "An &#128512;awesome &#128515;string with a few &#128521;emojis!"

String resultHexadecimal = EmojiParser.parseToHtmlHexadecimal(str);
System.out.println(resultHexadecimal);
// Prints:
// "An &#x1f600;awesome &#x1f603;string with a few &#x1f609;emojis!"

By default, any Fitzpatrick modifier will be removed. If you want to ignore the Fitzpatrick modifiers, use EmojiParser#parseToAliases(String, FitzpatrickAction). Examples:

String str = "Here is a boy: \uD83D\uDC66\uD83C\uDFFF!";
System.out.println(EmojiParser.parseToHtmlDecimal(str));
System.out.println(EmojiParser.parseToHtmlDecimal(str, FitzpatrickAction.PARSE));
System.out.println(EmojiParser.parseToHtmlDecimal(str, FitzpatrickAction.REMOVE));
// Print 3 times: "Here is a boy: &#128102;!"
System.out.println(EmojiParser.parseToHtmlDecimal(str, FitzpatrickAction.IGNORE));
// Prints: "Here is a boy: &#128102;🏿!"

The same applies for the methods EmojiParser#parseToHtmlHexadecimal(String) and EmojiParser#parseToHtmlHexadecimal(String, FitzpatrickAction).

Remove emojis

You can easily remove emojis from a string using one of the following methods:

  • EmojiParser#removeAllEmojis(String): removes all the emojis from the String
  • EmojiParser#removeAllEmojisExcept(String, Collection<Emoji>): removes all the emojis from the String, except the ones in the Collection
  • EmojiParser#removeEmojis(String, Collection<Emoji>): removes the emojis in the Collection from the String

For example:

String str = "An 😀awesome 😃string with a few 😉emojis!";
Collection<Emoji> collection = new ArrayList<Emoji>();
collection.add(EmojiManager.getForAlias("wink")); // This is 😉

System.out.println(EmojiParser.removeAllEmojis(str));
System.out.println(EmojiParser.removeAllEmojisExcept(str, collection));
System.out.println(EmojiParser.removeEmojis(str, collection));

// Prints:
// "An awesome string with a few emojis!"
// "An awesome string with a few 😉emojis!"
// "An 😀awesome 😃string with a few emojis!"

Extract Emojis from a string

You can search a string of mixed emoji/non-emoji characters and have all of the emoji characters returned as a Collection.

  • EmojiParser#extractEmojis(String): returns all emojis as a Collection. This will include duplicates if emojis are present more than once.

Credits

emoji-java originally used the data provided by the github/gemoji project. It is still based on it but has evolved since.

Available Emojis

See a table of the available emojis and their aliases HERE.