How to insert a new data into the list?



  • I am doing automaton. I'm reading the data from database and select the specific data. Here my database contains a sequence number list. Initially I put it into a array list.

    This is the db sequence number:

    [1,2,3,1.5,5,6,7,4,5,6,7,12,13,1.75,4.5,16,17,6.5,7,12,13,16,17,24,25,14.50,14.51,6.75,7,12,13,14.5,14.51,16,17,24,25,38,39,31.5,41]
    

    I am looping to check if(current value < previous value)..(1.5

    Here immediate greater value of 1.5 is 2, then the array list looks like this :

    • the first array [1,2,3] then [1,1.5,2,3,5,6] - here 1.5 is inserted before 2
    • second- [1,1.5,2,3,4,5,6,7,12,13] here 4 is inserted before 5
    • third- [1,1.5,1.75,2,3,4,5,6,7,12,13] here 1.75 is inserted before 2

    public static void insertBefore() {
        int next=0;
    
        //here seqNo contains list of sequence number from db.
        List seqNo=new ArrayList();
    
        for(int i=0;iseq[s+1] {  //[1,2,3,1.5]
                next=seq[s+1]
                seqNo.sort(); //[1,1.5,2,3]
                seqNo.indexof(next); //take index value as 1
            }
        }
    }
    ```
    
    
    

    Here I have a concern about this function mainly used to identify the cell value from GUI application from using specfic index. I am able to get the exact cell value from GUI, but this function is called only when previous value greater than current value.

    So others are normal entry events. So whenever this function is called I need to take next value means 7 and 4 then need to take the index value from that list. The list is [1,1.5,2,3,5,6,7] like this, then again this function is called, then I need to check 13 and 1.75 [1,1.5,2,3,4,5,6,7,12,13]. This should be continued, how it is possible?



  • If you have a list with all those items just do:

    list.sort()
    

    Here is the doc for List methods: https://docs.oracle.com/javase/8/docs/api/java/util/List.html


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2