Home>Article>Java> How to determine whether char is a space in java

How to determine whether char is a space in java

王林
王林 Original
2019-11-28 09:22:39 7071browse

How to determine whether char is a space in java

函数介绍:

toCharArray()方法将字符串转换为字符数组。

语法:

public char[] toCharArray()

返回值:

字符数组。

在线视频教程推荐:java学习视频

判断思路:

首先通过调用“toCharArray”方法将需要判断的字符串保存到字符数组中,然后使用“for”循环判断字符数组的长度,通过长度的判断来确定“char”是否是空格。

示例如下:

//判断是否char是否为空 import java.util.*; public class test{ public static void main(String[] args){ String str="abc abc"; char [] ch=str.toCharArray(); for(int i=0;i
      

扩展知识:

//判断char是否为空字符串 char M='A'; if(M!='\0'){ System.out.println("字符M不为空"); } char[] N=new char[1]; if(N[0]=='\0') System.out.println("字符N[0]为空\n\n\n\n");

相关文章教程推荐:java入门程序

The above is the detailed content of How to determine whether char is a space in java. 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