如何在java中替换空值空字符串? [英] How to replace from null value empty string in java?

查看:378
本文介绍了如何在java中替换空值空字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从DB获取 null 值,但我需要显示空字符串

I'm getting the null values from DB, but I need to display the empty string "" instead.



例如,我必须附加四个值才能显示在Excel工作表的单个单元格中,如下所示:


For example, I have to append four values to display in the single cell of a Excel sheet like below:

sheet.addCell(new Label(4, currentRow, a.getPar()+" "+a.getO()+" "+a.getPar()));



如何在Java中实现预期的结果(替换)? / p>


How to achieve the expected result (the replacement) in Java?

推荐答案

如果我理解正确,你可以使用三元opperator:

If I understand correctly, you can use the ternary opperator:

System.out.println("My string is: " + ((string == null) ? "" : string));

如果你不熟悉它,它会显示Is string null?如果是,那么'return'en empty string,否则'return'string。我说'return'因为你可以考虑((string == null)?:string)作为一个返回 String的函数

In case you are not familiar with it, it reads "Is string null? If it is, then 'return' en empty string, else 'return' string". I say 'return' because you can consider ((string == null) ? "" : string) as a function that returns a String.

当然,您可以将空字符串替换为任何其他字符串

You can replace the empty string with any other String of course.

这篇关于如何在java中替换空值空字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆