Here's an improved version of Darko's answer:
public static boolean isRtl(String string) { if (string == null) { return false; } for (int i = 0, n = string.length(); i < n; ++i) { byte d = Character.getDirectionality(string.charAt(i)); switch (d) { case DIRECTIONALITY_RIGHT_TO_LEFT: case DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC: case DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING: case DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE: return true; case DIRECTIONALITY_LEFT_TO_RIGHT: case DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING: case DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE: return false; } } return false; }
This code works for me for all of the following cases:
בוקר טוב => true good morning בוקר טוב => false בוקר טוב good morning => true good בוקר טוב morning => false בוקר good morning טוב => true (בוקר טוב) => true
source share