java - Get an array slice of 2d array -
i have got 2d string array. how can check slice of it? example row 3, 6th element there
i have tried
string arr[][] = new string[3][6] arr[3][4] = "example" if (arrays.aslist(arr).sublist(3,6).contains("example")) system.out.print("yes"); but doesn't work. works 1d array? also, instead of using contains how can 1 check whether elements null in slice array?
first of all, arrays zero-indexed in java, if declare array first dimension 3, maximum index 2.
second, if want @ slices of third row, should specify index 2 explicitly before converting list.
import java.util.*; public class arraygame { public static void main(string[] args) { string arr[][] = new string[3][6]; arr[2][4] = "example"; if (arrays.aslist(arr[2]).sublist(3,6).contains("example")) system.out.println("yes"); } } output:
yes
Comments
Post a Comment