toString java of arrays

前端 未结 4 807
旧巷少年郎
旧巷少年郎 2020-12-03 15:20

I have several arrays in a class

I want to implement toString() to print all values.

How to do this?

public String var1[];   
public int var2         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 15:41

    First of all, it depends on the size of your arrays. You did not mention any size for each of it. Of course, we can use for each. The second question obviously, how to want to print them all in the screen. that is the matter.

    In case, if you go with normal for loop [ex: for(int i=0;i in this case. You have to go by individual loop for each array.

    If your array size is same for all. You can simply use one loop to iterate all of them to print it off.

    Hint: don't forget to handle the ArrayOutofBound exception. You would need that :P

提交回复
热议问题