Home  >  Article  >  Java  >  Which function in java can get the length of a string

Which function in java can get the length of a string

王林
王林Original
2020-06-22 13:20:535742browse

Which function in java can get the length of a string

The length() function in java can get the length of a string.

(Recommended tutorial: java introductory program)

The length() method in Java String is used to obtain the length of the string and use it as an int variable Returns the length of this string.

Syntax:

length();

Example:

Use the length() function to get the length of the string strCom2, and assign the returned result to the int type variable length.

String strCom2="php中文网";
int length=strCom2.length();

(Video tutorial recommendation: java video tutorial)

The above is the detailed content of Which function in java can get the length of a string. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn