如何知道字符串variabel在Java中是否仅包含空格? [英] How to know if the string variabel contains only space in java?
本文介绍了如何知道字符串variabel在Java中是否仅包含空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个变量,它是一个字符串,如果变量仅包含一个或多个空格,我想将字符串替换为"null".我该怎么办?
I have a variable that's a string and I want to replace the string with "null" if the variable contains only a space or multiple spaces. How can I do it?
推荐答案
尝试以下操作:
if(str.trim().isEmpty()){
str = null;
}
这篇关于如何知道字符串variabel在Java中是否仅包含空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文