# java.text.spi

***

**1. Getting an Instance of NumberFormat**

```java
NumberFormat numberFormat = NumberFormat.getInstance();
```

**2. Setting the Currency**

```java
NumberFormat numberFormat = NumberFormat.getCurrencyInstance();
numberFormat.setCurrency(Currency.getInstance("USD"));
```

**3. Formatting a Number as Currency**

```java
double amount = 1234.56;
String formattedAmount = numberFormat.format(amount); // "$1,234.56"
```

**4. Parsing a Currency String**

```java
String currencyString = "$1,234.56";
Number parsedAmount = numberFormat.parse(currencyString); // 1234.56
```

**5. Getting an Instance of DateFormat**

```java
DateFormat dateFormat = DateFormat.getInstance();
```

**6. Setting the Date Format**

```java
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL);
```

**7. Formatting a Date**

```java
Date date = new Date();
String formattedDate = dateFormat.format(date); // "Friday, April 22, 2023"
```

**8. Parsing a Date String**

```java
String dateString = "2023-04-22";
Date parsedDate = dateFormat.parse(dateString); // Thu Apr 22 00:00:00 CST 2023
```

**9. Getting an Instance of DecimalFormat**

```java
DecimalFormat decimalFormat = new DecimalFormat();
```

**10. Setting the Decimal Format**

```java
DecimalFormat decimalFormat = new DecimalFormat("#.##");
```

**11. Formatting a Number**

```java
double value = 123.456;
String formattedValue = decimalFormat.format(value); // "123.46"
```

**12. Parsing a Number String**

```java
String numberString = "123.456";
Number parsedValue = decimalFormat.parse(numberString); // 123.456
```

**13. Getting an Instance of MessageFormat**

```java
MessageFormat messageFormat = new MessageFormat("{0} is {1} years old.");
```

**14. Setting the Arguments**

```java
Object[] arguments = {"John", 30};
```

**15. Formatting a Message**

```java
String formattedMessage = messageFormat.format(arguments); // "John is 30 years old."
```

**16. Parsing a Message**

```java
String message = "John is 30 years old.";
Object[] parsedArguments = messageFormat.parse(message); // {"John", 30}
```

**17. Getting an Instance of ChoiceFormat**

```java
ChoiceFormat choiceFormat = new ChoiceFormat(
    "0#no files | 1#one file | 2#two files | 1<{0} files");
```

**18. Selecting the Format**

```java
int numberFiles = 5;
String formattedMessage = choiceFormat.format(numberFiles); // "5 files"
```

**19. Parsing a Formatted Message**

```java
String message = "5 files";
Number parsedNumber = choiceFormat.parse(message); // 5
```

**20. Getting an Instance of Collator**

```java
Collator collator = Collator.getInstance();
```

**21. Setting the Locale**

```java
Locale locale = Locale.GERMAN;
collator = Collator.getInstance(locale);
```

**22. Comparing Strings**

```java
String string1 = "Apple";
String string2 = "Orange";
int result = collator.compare(string1, string2); // -1
```

**23. Getting an Instance of Normalizer**

```java
Normalizer normalizer = Normalizer.getInstance();
```

**24. Normalizing a String**

```java
String string = "Türkiye";
String normalizedString = normalizer.normalize(string); // "Turkiye"
```

**25. Getting an Instance of BreakIterator**

```java
BreakIterator breakIterator = BreakIterator.getWordInstance();
```

**26. Setting the Text**

```java
String text = "Hello, world!";
breakIterator.setText(text);
```

**27. Getting the Boundaries**

```java
int boundary = breakIterator.first();
while (boundary != BreakIterator.DONE) {
  System.out.println(text.substring(boundary, breakIterator.next()));
  boundary = breakIterator.next();
}
```

**28. Getting an Instance of CharacterIterator**

```java
CharacterIterator characterIterator = new StringCharacterIterator("Hello, world!");
```

**29. Navigating the Characters**

```java
char character = characterIterator.current();
while (character != CharacterIterator.DONE) {
  System.out.print(character);
  character = characterIterator.next();
}
```

**30. Getting an Instance of Locale**

```java
Locale locale = Locale.getDefault();
```

**31. Getting the Language**

```java
String language = locale.getLanguage(); // "en"
```

**32. Getting the Country**

```java
String country = locale.getCountry(); // "US"
```

**33. Getting an Instance of Currency**

```java
Currency currency = Currency.getInstance("USD");
```

**34. Getting the Currency Code**

```java
String currencyCode = currency.getCurrencyCode(); // "USD"
```

**35. Getting an Instance of TimeZone**

```java
TimeZone timeZone = TimeZone.getDefault();
```

**36. Getting the Time Zone ID**

```java
String timeZoneID = timeZone.getID(); // "America/Los_Angeles"
```

**37. Getting an Instance of SimpleDateFormat**

```java
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
```

**38. Setting the Time Zone**

```java
simpleDateFormat.setTimeZone(timeZone);
```

**39. Formatting a Date**

```java
Date date = new Date();
String formattedDate = simpleDateFormat.format(date); // "2023-04-22"
```

**40. Parsing a Date String**

```java
String dateString = "2023-04-22";
Date parsedDate = simpleDateFormat.parse(dateString); // Thu Apr 22 00:00:00 CST 2023
```

**41. Getting an Instance of DecimalFormatSymbols**

```java
DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols();
```

**42. Getting the Decimal Separator**

```java
char decimalSeparator = decimalFormatSymbols.getDecimalSeparator(); // '.'
```

**43. Getting the Currency Symbol**

```java
String currencySymbol = decimalFormatSymbols.getCurrencySymbol(); // "$"
```

**44. Getting an Instance of MessageFormat**

```java
MessageFormat messageFormat = MessageFormat.getInstance();
```

**45. Setting the Pattern**

```java
messageFormat.setPattern("{0} is {1} years old.");
```

**46. Setting the Arguments**

```java
Object[] arguments = {"John", 30};
```

**47. Formatting a Message**

```java
String formattedMessage = messageFormat.format(arguments); // "John is 30 years old."
```

**48. Parsing a Message**

```java
String message = "John is 30 years old.";
Object[] parsedArguments = messageFormat.parse(message); // {"John", 30}
```

**49. Getting an Instance of MessageFormat**

```java
MessageFormat messageFormat = new MessageFormat("{0} is {1} years old.");
```

**50. Getting the Available Locales**

```java
Locale[] availableLocales = MessageFormat.getAvailableLocales();
```
