java - How to sort the string ArrayList? -


i parsing json array successfully. have string has numbers. want sort data according numbers. had been checked many examples couldn't implement them in code.so please me. here code. here "count" the, string threw want sort data.

a.java

    @override     protected void doinbackground(void... params) {         servicehandler servicehandler = new servicehandler();         string jsonstr = servicehandler.makeservicecall(                 jsonurl.categoriesurl, servicehandler.get);         log.d("response categories:", ">" + jsonstr);         if (jsonstr != null) {             try {                 jsonobject jsonobj = new jsonobject(jsonstr);                 categoriesjsonarray = jsonobj                         .getjsonarray(jsonurl.tag_data);                  (int = 0; < categoriesjsonarray.length(); i++) {                     jsonobject c = categoriesjsonarray.getjsonobject(i);                      gridviewitem gridcategoriesitem = new gridviewitem();                     gridcategoriesitem.setslug(c                             .getstring(jsonurl.tag_categories_slug));                     gridcategoriesitem.setimage(c                             .getstring(jsonurl.tag_categories_image));                     gridcategoriesitem.setcount(c                             .getstring(jsonurl.tag_categories_count));                      mgridarraycategories.add(gridcategoriesitem);                      }             } catch (jsonexception e) {                 e.printstacktrace();             }         } else {             log.d("servicehandler", "couldn't data url");         }         return null;     } 

gridviewitem.java

public class gridviewitem { string image; string slug; string count; string name;  public gridviewitem() {     super(); }  public gridviewitem(string image, string slug, string count,         string name) {     super();     this.image = image;     this.slug = slug;     this.count = count;     this.name = name; }  public string getimage() {     return image; }  public void setimage(string image) {     this.image = image; }  public string getslug() {     return slug; }  public void setslug(string slug) {     this.slug = slug; }  public string getcount() {     return count; }  public void setcount(string count) {     this.count = count; }  public string getname() {     return name; }  public void setname(string name) {     this.name = name; } } 

you can use collection.sort().

for sorting kind of arraylsit object.

 collections.sort(listofstringarrays,new comparator<string[]>() {             public int compare(string[] strings, string[] otherstrings) {                 return strings[1].compareto(otherstrings[1]);             }         }); 

Comments

Popular posts from this blog

C# random value from dictionary and tuple -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -