Logo

Programming-Idioms

History of Idiom 169 > diff from v94 to v95

Edit summary for version 95 by programming-idioms.org:
[Java] Emphasis in comments

Version 94

2021-12-13, 13:41:28

Version 95

2021-12-13, 13:41:54

Idiom #169 String length

Assign to integer n the number of characters of string s.
Make sure that multibyte characters are properly handled.
n can be different from the number of bytes of s.

Idiom #169 String length

Assign to integer n the number of characters of string s.
Make sure that multibyte characters are properly handled.
n can be different from the number of bytes of s.

Variables
n,s
Variables
n,s
Extra Keywords
size characters chars number runes
Extra Keywords
size characters chars number runes
Code
int n = s.length();
Code
int n = s.length();
Comments bubble
This works only if s != null.

If s == null, this throws a NullPointerException.
Comments bubble
This works only if s != null.

If s == null, this throws a NullPointerException.
Doc URL
https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#length()
Doc URL
https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#length()