Is there a way to convert an Array<Int> to an Int in Kotlin? I am messing with 2D arrays and am trying to print the elements whose indexes are equal to each other. Here is my loop that tries to accomplish this:
for (rows in arr) {
for (elements in rows) {
--------> if (rows == elements) {
print(elements)
}
}
print("\n")
}
rows is type Array<Int> and elements is type Int. I have already tried using the StringBuilder method and that does not work. Is there a function or other method that allows this? Any tips for me to do further research is appreciated.
4is at[1][1]?if(i < j)then all of the elements below the main diagonal would be printed out. The solution that @andras stated showed me that there is a.sizefunction to get the entire length of the array and that was my missing piece to my problem.