I have coded several months in Python, and now I need to switch to Java for work related reasons. My question is, is there a way to mimic this type of expression
if var_name in list_name: # do something
without defining an extra isIn()-like boolean function that scans list_nameto find var_name?
isIn()
list_name
var_name
You are looking for List#containsone that is inherited from Collection#contains(so you can use it with objects too Set)
List#contains
Collection#contains
Set
if (listName.contains(varName)) { // doSomething }
true, . , true , e , (o == null? e == null: o.equals(e)).
, List#contains equals true false. , , hashcode.
equals
hashcode
List.contains(object), , , , . , .
java.util.ArrayList.contains(Object) true, .
List list=new ArrayList(); list.add(1); list.add(2); if(list.contains(2)){ //do something }
contains - , . :
boolean return_flag = list_name.contains(var_name) if return_flag{ //do stuff }
if list_name.contains(var_name){ //do stuff }
.