Avatar of Tore
Flag for Norway

asked on 

Sort 2 dim String table + search for string

Trying to figure out how to sort a 2 dimensional String table, but it seems like all suggestions on the web is avoiding the problem. 

Arrays.sort(...) does not work well on string tables

was thinking of Arrays.binarySearch

Do i have to in some way rely on ArrayList ?

or am I barking up the wrong tree ?

package no.test.basic.stringtable;
import java.util.Arrays; public class TwoDimStringTable {     public static void main(String [] args) {         String[][] sTabell = new String[8][2];         sTabell[0][0] =  "Ola";         sTabell[1][0] =  "var";         sTabell[2][0] =  "fra";         sTabell[3][0]=   "Sandefjord";         sTabell[4][0] =  "Han";         sTabell[5][0] =  "var";         sTabell[6][0] =  "lettmatros";         sTabell[7][0] =  "ombord!";         sTabell[0][1] =  "Ola";         sTabell[1][1] =  "kunne";         sTabell[2][1] =  "engelsk";         sTabell[3][1]=   "ei";         sTabell[4][1] =  "men";         sTabell[5][1] =  "han";         sTabell[6][1] =  "klarte";         sTabell[7][1] =  "seg";                 for (int i = 0; i <= sTabell.length-1; i++) {             System.out.println(sTabell[i][0] + "  " + sTabell[i][1]);         }  // what next for sorting // what next for searching for the string "klarte" to get position of element         }   }

Open in new window


Avatar of undefined
Last Comment

8/22/2022 - Mon