Java: Initialize multiple variables in for loop init?

后端 未结 4 1641
夕颜
夕颜 2020-11-30 02:24

I want to have two loop variables of different types. Is there any way to make this work?

@Override
public T get(int index) throws IndexOutOfBoundsException          


        
4条回答
  •  野性不改
    2020-11-30 02:42

    Variables declared in the initialization block must be of same type

    we can't initialize the different data types in the for loop as per their design. I'm just putting a small example.

    for(int i=0, b=0, c=0, d=0....;/*condition to be applied */;/*increment or other logic*/){
          //Your Code goes here
    }
    

提交回复
热议问题