2021年3月10日星期三

Is there an where method in java like python

IN python,if you want to get which index in x equals 2 you can do

x = [1,2,3,4,0,1,2,3,4,11]   x=np.array(x)  np.where(x == 2)    

but is there any simple way to do the same effect in java arraylist? i want find all index in x equal to given condition

In java i only find indexof method but it can not work

here is my java code:

public class List_demo {      public static void main(String[] args) {          int s1=1;          int s2=2;          int s3=2;          int s4=2;          List list=new ArrayList();          list.add(s1);          list.add(s2);          list.add(s3);          list.add(s4);          for(int i=0;i<list.size();i++) {              System.out.println(list.get(i));          }      }    }    
https://stackoverflow.com/questions/66575882/is-there-an-where-method-in-java-like-python March 11, 2021 at 11:06AM

没有评论:

发表评论