Hi all;
how can i find equal string in 2D array in java in this program,,
i mean in this code i have 2D array 2 rows and 4 columns,for example in my code
the equal string is "orange" ,,so how can search for any equal string in 2D array ??

 public static void main(String[] args) {

            String[][] t={{"hellow","happy","life","orange"},{"blue","orange","door","apple"}};

            for (int i = 0; i < t.length; i++) {
                for (int j = 0; j < t[i].length; j++) {

                    System.out.print(t[i][j] + " ");
                }
                System.out.println();

                }



}}
Re: search for equal string in 2D array in java 80 80

Inside your nested loops just use the equals method to compare t[i][j] with the target string.

Re: search for equal string in 2D array in java 80 80

Thanks , I use it but I mean if can I compare the positions that contain target string for example in my code the string orange is in the position (0,3) and (1,1) how can I compare to get the equal string in 2d array ...?

Re: search for equal string in 2D array in java 80 80

... by following James' suggestion:
if ( t[0][3].equals(t[1][1])

Re: search for equal string in 2D array in java 80 80

Ok...thank you very much ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.