<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-can-you-get-the-number-of-characters-in-a-string---cracking-the-java-coding-interview-b28y3ibmt" -->

---
title: How can you get the number of characters in a String? -...
description: A Java interview question exploring the nuances of String.length() — it returns the number of Unicode code units (16-bit chars), not necessarily the number of...
canonical: https://daily.dev/posts/how-can-you-get-the-number-of-characters-in-a-string---cracking-the-java-coding-interview-b28y3ibmt
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How can you get the number of characters in a String? - Cracking the Java Coding Interview | daily.dev
og:description: A Java interview question exploring the nuances of String.length() — it returns the number of Unicode code units (16-bit chars), not necessarily the number of...
og:url: https://daily.dev/posts/how-can-you-get-the-number-of-characters-in-a-string---cracking-the-java-coding-interview-b28y3ibmt
og:image: https://api.daily.dev/og/posts/B28Y3ibMt.png
og:image:alt: How can you get the number of characters in a String? - Cracking the Java Coding Interview
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How can you get the number of characters in a String? - Cracking the Java Coding Interview

**[Java \(Official Oracle\)](https://daily.dev/sources/java-oracle)** · 1 min read · 0 upvotes · 0 comments

## Summary

A Java interview question exploring the nuances of String.length() — it returns the number of Unicode code units (16-bit chars), not necessarily the number of visible characters. Some Unicode characters require two code units (a surrogate pair), so a string displaying one character on screen can have a length of 2 or more. The distinction between code units (char) and code points (int) is introduced as a key concept.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=7al_ZQn99CY>

## Similar posts on daily.dev

- [Count the Number of Times a Sequence Occurs in a Java String](https://daily.dev/posts/count-the-number-of-times-a-sequence-occurs-in-a-java-string-jvfhdm62x) · Baeldung · 4 upvotes · 0 comments

---

Tags: [#java](https://daily.dev/tags/java)

[View this post on daily.dev](https://daily.dev/posts/how-can-you-get-the-number-of-characters-in-a-string---cracking-the-java-coding-interview-b28y3ibmt)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How can you get the number of characters in a String? - Cracking the Java Coding Interview","url":"https://daily.dev/posts/how-can-you-get-the-number-of-characters-in-a-string---cracking-the-java-coding-interview-b28y3ibmt","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-can-you-get-the-number-of-characters-in-a-string---cracking-the-java-coding-interview-b28y3ibmt"},"datePublished":"2026-07-17T10:23:05.334Z","dateModified":"2026-07-17T10:23:21.697Z","description":"A Java interview question exploring the nuances of String.length() — it returns the number of Unicode code units (16-bit chars), not necessarily the number of...","image":"https://i.ytimg.com/vi/7al_ZQn99CY/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/7al_ZQn99CY/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Java (Official Oracle)","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Java (Official Oracle)","logo":"https://media.daily.dev/image/upload/s--SM9hIYUY--/f_auto,q_auto/v1773648791/logos/java-oracle?_a=BAMAMiiu0","url":"https://daily.dev/sources/java-oracle"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-can-you-get-the-number-of-characters-in-a-string---cracking-the-java-coding-interview-b28y3ibmt","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"java","timeRequired":"PT1M","video":{"@type":"VideoObject","name":"How can you get the number of characters in a String? - Cracking the Java Coding Interview","description":"A Java interview question exploring the nuances of String.length() — it returns the number of Unicode code units (16-bit chars), not necessarily the number of...","thumbnailUrl":"https://i.ytimg.com/vi/7al_ZQn99CY/sddefault.jpg","uploadDate":"2026-07-17T10:23:05.334Z","duration":"PT1M","url":"https://api.daily.dev/r/B28Y3ibMt","embedUrl":"https://www.youtube.com/embed/7al_ZQn99CY"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Java (Official Oracle)","item":"https://daily.dev/sources/java-oracle"},{"@type":"ListItem","position":3,"name":"How can you get the number of characters in a String? - Cracking the Java Coding Interview"}]}
```

