在类中使用数组数组重复结果

时间:2017-11-11 04:18:17

标签: java arraylist

我是java的新手,我需要将一堆对象的内容保存到一个数组中,该数组将具有一个数组属性,并且数组属性也有一个数组属性我知道它很复杂但我需要这样做,因为它看起来像一张桌子。无论如何,这是我的代码

//First class
     public static class classA //inner
              { public char sy;
                public ArrayList <Integer> arrystateA;
                public classA()
               { sy='0';
                 arrystateA= new ArrayList <Integer>();} }

//The second class 

     public static  class ArrayofclassA// meddile
              { int num;
                public ArrayList <classA> arrystateB;  
                public ArrayofclassA()
              {    arrystateB=new ArrayList < classA>();
                   num=-1;}
                 public void creatrans(classA z)
                  { arrystateB.add(z);
                } }

这是主要代码

classA temp2=new classA();
                    ArrayofclassA temp3 = new ArrayofclassA();
                  ArrayList<ArrayofclassA> NFAtranstable=new ArrayList<ArrayofclassA>();



                       while(!reslt.empty()){
                           temp=reslt.pop();
                          for (int i=0;i<NFAtranstable.size();i++)
                           {temp3=NFAtranstable.get(i);
                              if (temp3.num==temp.s_to)
                              {
                                  if(temp3.arrystateB.get(i).sy==temp.t_sym)
                                  {
                                    temp3.arrystateB.get(i).arrystateA.add(temp.s_to);  
                                     match=true;


                                  }else
                                      {temp2.sy=temp.t_sym;temp2.arrystateA.add(temp.s_to);
                                      temp3.creatrans(temp2);

                                      match=true;

                                      }
                                  }
                              }

                           if(!match)
                           {

                               temp2.sy=temp.t_sym;
                               temp2.arrystateA.add(temp.s_to);
                               temp3.num=temp.s_from;
                              temp3.arrystateB.add(temp2);
                               NFAtranstable.add(temp3);




                           }
                           match=false;
                           }



                       for(int i=0;i<NFAtranstable.size();i++)
                           { 
                           System.out.print(NFAtranstable.get(i).num+"      "); 
                           for(int j=0;j<NFAtranstable.get(i).arrystateB.size();j++)
                           {
                              System.out.println(NFAtranstable.get(i).arrystateB.get(j).sy+"      ");

                             for(int k=0;k<NFAtranstable.get(i).arrystateB.get(j).arrystateA.size();k++)
                               {
                                   System.out.print(NFAtranstable.get(i).arrystateB.get(j).arrystateA.get(k));
                               }
                           }
                     }
               }

当我打印阵列的内容时,NFAtranstable&#39;它给了我重复的结果,就像只保存相同的价值,它已经大约8个小时了,我找不到问题=(

0 个答案:

没有答案