!college.equals("no")怎么将"no"改成null
时间: 2023-11-30 07:02:56 浏览: 28
你可以直接将 "no" 替换为 null,代码如下:
```
college = (college.equals("no")) ? null : college;
```
这里使用了 Java 中的条件运算符(ternary operator),如果 college 等于 "no",则将其赋值为 null,否则保持原值。
相关问题
!Objects.equals(Choice, "Yes")||!Objects.equals(Choice,"No")为什么始终为假
这个表达式中使用了逻辑或(||)运算符,只有两个条件中至少有一个为真,整个表达式才会被计算为真。但是,这个表达式中的两个条件是互斥的,即Choice只能是"Yes"或"No",它不可能既等于"Yes"又等于"No"。因此,无论Choice的值是什么,至少有一个条件会被判定为假,整个表达式就会被判定为假。
string != null && !string.equals("")
This is a condition that evaluates to true if the string is not null. In other words, it checks whether the string variable has a value assigned to it or not. If the string is null, the condition would evaluate to false.