I want to create an array with for example integer values. In my Code below I create a while loop where I get an long string with much informations but now I need only 1 number value from this String, I get this number with the substring Method.
How is it possible to fill this substring into an array. Everytime in the while loop I get a new line from my file where are the Strings. And every time the number is different.
Here is my Code:
public static void main(String[] args) {
         Text m;
          String a;
         Set<Integer> set = new HashSet<>();
          try {
             m = new Text();
             while(m.hasLine) {
                a = m.nextline(); // Here I get the string which looks like :  <name id="654" time="123"  number=”345”  value=”789” />
                String z2 = a.substring(10,13);     // Here I get String : 654
                String z3 = a.substring(21,24);     // String: 123
                String z4 = a.substring(35,38);     // String: 345
                String z5 = a.substring(48,51);     // String: 789
                String z6 = a.substring(60,64);     // String: 4326
                Integer i2 = Integer.valueOf(z2);   //Convert all to integer values
                Integer i3 = Integer.valueOf(z3);
                Integer i4 = Integer.valueOf(z4);
                Integer i5 = Integer.valueOf(z5);
                Integer i6 = Integer.valueOf(z6); 
                //System.out.println(z2);
                String r1;
                if(set.contains(i2)){                     // If The ID is in my array don't set it in the array only create string r1 with MEssage:2
                     r1 = "{\"Message\":2,";
                   }
                    else{
                         set.add(i2);                     // If the ID is not in my arrray set it in my array and create string r2 with Message: 1
                         r1 = "{\"Message\":1,";
                    }
               // 1. How can I  expand this array for the values  of time; number; and value . So if the ID Value isn't in the array put it in there with the 4 values. and create String with Message: 2
               // 2. And if the ID is in there check if value time is the same , if not , create String with Message 2
               // 3. And if the ID is in there check if value time is not the same, then check if value number and value is the same ... if yes Create string Message 3: for example
                // So how can I do such a thing. where I can create a 4 dimensional array and check if the values so in there ???
             String s = r1;
                System.out.println(s);
             }
          }catch (FileNotFoundException e) {
                 System.out.println("File not found!");
    }
}
}
SO the main thing i want to do is in my while loop I get everytime the next line from my document. Line for Line!. Every Line I get as a String and in every String is an ID number. Now I want to create an array only with this id numbers. The reason why I want to do this, I have large document and it could be that one id is multiple times in there and in future I want for every line first to check if this id number is in my array and if it is there it should not fill this id in my array, because it is still there.
I hope you understand what I want to do !
Thank You very much !