java - move items in linked list -


how move items , down position in linked list?

the text file contains data follows saved in linked list. want sort items according first items, i.e ty12354, ytpy217,ty12354dsaf....

ty12354, toyota, ty1257,2100000 sk2344, skoda, so2345, 180000 ytpy217,safsadf,asfasf,1241234 ty12354d,sfasdf,asfasf,235123412 ty12354dsaf,asdffasd,asfasfafsd,12344 abc123,asdffasd,asfasfafsd,12344

i used following code sorting, doesn't work:

    (int x = 0;x < (lstcar.size()-1); x++) {                 c=(car) lstcar.get(x);  //lstcar linked list     d = (car) lstcar.get(x+1);     int compare =d.getregnumber().compareto(c.getregnumber())  ;     if(compare < 0){          temp = d;         lstcar(x)=c;  //tried method doesnt work         //lstcar.sort();          c = temp;     }                  } 

this not right way set element in linkedlist:

  lstcar(x)=c;  //tried method doesnt work 

instead use:

  lstcar.set(x,c); 

if want sort list keeping approach (i.e. doing shown), method .set(index, element) work you.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -