Application scenario (Exchange depth increment push)
- [[411.8,6],[411.75,11],[411.6,22],[411.5,9],[411.3,16]]
- [[411.8,5],[411.7,11],[411.5,22],[411.5,9],[411.3,1]]
ImportJava.util.ArrayList;ImportJava.util.List; Public class a { Public Static void Main(string[] args) {/** * Two sets are ordered, from large to small * 1). The collection now has a collection of old no, add * * 2). Collection now there's a collection of all that is present, discard * * 3). The collection now does not have but the collection old has, the quantity flag bit 0 * * 4). The collection now has a set of existing but inconsistent changes in number. //string[] Length is 2 The first data is price, the second data is the quantityList<string[]> now =NewArraylist<string[]> (); list<string[]> old =NewArraylist<string[]> (); StringBuilder data =NewStringBuilder ();//For stitching the final data intOldsize = Old.size ();intNowsize = Now.size ();intindex =0;//Now Collection index intLast_index =0;//Old collection index for(inti =0, size = Oldsize + nowsize; i < size; i++) {if(Last_index >= oldsize && index >= nowsize) {//If each element of two data is consistent Break; }DoublePrice =-1D String amount ="";if(Index < Nowsize) {Price = Double.parsedouble (Now.get (index) [0]); Amount = Now.get (index) [1]; }DoubleLastprice =-1D String Lastamount ="";if(Last_index < Oldsize) {Lastprice = double.parsedouble (Old.get (Last_index) [0]); Lastamount = Old.get (Last_index) [1]; }if(Price = = Lastprice) {if(!amount.equals (Lastamount)) {Data.append ("["+ Price +","+ Amount +"],"); } last_index++; index++; }Else if(Price > Lastprice) {Data.append ("["+ Price +","+ Amount +"],"); index++; }Else if(Price < Lastprice) {Data.append ("["+ Price +","+0+"],"); last_index++; } } }}
Compare two ordered sets