list.contains不起作用.这是我从数据库中获取数据的列表.
////////List/////////////////
public List<Comment> getAllComments() {
List<Comment> comments = new ArrayList<Comment>();
Cursor cursor = database.query(MySQLiteHelper.TABLE_COMMENTS,
allColumns, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Comment comment = cursorToComment(cursor);
comments.add(comment);
cursor.moveToNext();
}
// make sure to close the cursor
cursor.close();
return comments;
}
/////////////////////////////////////////////
datasource = new CommentsDataSource(this);
datasource.open();
final List list;
list = datasource.getAllComments();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(list.contains("Hello")){
Toast.makeText(getApplicationContext(), "List Contains data", Toast.LENGTH_SHORT).show();
} ///////Here it always return false///////
else{
Toast.makeText(getApplicationContext(), "Data not …Run Code Online (Sandbox Code Playgroud) 假设我有一个函数:
fun equality() {
var a = "kotlin"
var b = "kotlin"
var c = a
println(a==b) //true
println(a===b) //false
println(a==c) //true
println(a===c) //true
}
Run Code Online (Sandbox Code Playgroud)
根据kotlin === a和b是不同的实例,所以我的预期输出是:
true
false
true
true
Run Code Online (Sandbox Code Playgroud)
但实际上显示:
true
true
true
true
Run Code Online (Sandbox Code Playgroud)
我不明白a === b是怎么回事。