как экспортировать 2D таблицу в Java - PullRequest
0 голосов
/ 28 мая 2010

Здравствуйте, я хотел бы спросить вас о 2D таблицах в Java! Мой код такой: я хотел бы создать систему, чтобы увидеть регистрацию в mytable citylink. Может кто-нибудь мне помочь?

  int i=0;
  while(i<=citylink.length) {
    for(Xml polh_is:fetchsite.child("site").child("poleis").children("polh")) { //url 
      if((polh_is.string("name")=="")||(polh_is.content()==""))//attribute
        error += "Error in polh: name is - " + polh_is.string("name") + " with url - " + polh_is.content() + " -.\n";
      else
        for(int j=0; j<citylink.length; j++) {
          citylink[j][0]=HtmlMethods.removeBreaks(polh_is.string("name"));
          citylink[j][1]=HtmlMethods.removeBreaks(polh_is.string("with url -"+polh_is.content() +"-.\n"));

          i++;
        }
    }
  }

Ответы [ 3 ]

0 голосов
/ 28 мая 2010

Как то так?:

StringBuilder citiesBuilder = new StringBuilder();
for (String[] city:citylink) {
  citiesBuilder.append(String.format("%s (URL: %s)%n", city[0], city[1]));
}
System.out.println(citiesBuilder.toString());

EDIT

изменил «города» на «Ситилинк» - моя ошибка. Но поверьте мне, это работает;) (Надеюсь, ваша Java как минимум 1.5)

ааа, и я полагаю, ситилинк имеет тип String[][]. В противном случае, предоставьте декларацию, чтобы я мог адаптировать код.

0 голосов
/ 28 мая 2010

Я не понимаю назначение второго цикла for: разве он не заполняет весь массив последним элементом?

Как насчет:

int i=0;
for(Xml polh_is:fetchsite.child("site").child("poleis").children("polh")) { //url 
  if((polh_is.string("name")=="")||(polh_is.content()==""))//attribute
    error += "Error in polh: name is - " + polh_is.string("name") + " with url - " + polh_is.content() + " -.\n";
  else if (i >= citylink.length)
     break; 
  else {
      citylink[i][0]=HtmlMethods.removeBreaks(polh_is.string("name"));
      citylink[i][1]=HtmlMethods.removeBreaks(polh_is.string("with url -"+polh_is.content() +"-.\n"));

      i++;
}
0 голосов
/ 28 мая 2010

Ситилинк представляется одномерным массивом? Вы можете использовать другой 2D-массив для хранения значений.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...