Skip to content
TheChatArchiveThe Chat Archive
Kimikimi-k2-0711-preview· Moonshot AIHugging Face LMArena Human Preference 140K

what is the best way to capitalizes first letter in the string? java 21 is used

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with o3-2025-04-16’s answer.
  1. User

    what is the best way to capitalizes first letter in the string? java 21 is used

  2. Kimi Assistant

    In Java 21, the cleanest and most idiomatic way to capitalize the first letter of a string is:

    String capitalized = str.isEmpty() ? str : Character.toUpperCase(str.charAt(0)) + str.substring(1);
    

    This handles empty strings safely and avoids unnecessary allocations.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.