I have an ArrayList that is populated with an object that has fields in it. I need to sort the data in this ArrayList by a piece of the data that is in my object. Is this possible? If so, how would I do it? Below is my code:
Bean code while loop that creates arraylist:
[CODE]
while (journalArticlesIterator.hasNext()) {
JournalArticle journalArticle = journalArticlesIterator.next();
String articleType = journalArticle.getType();
if (articleType.equalsIgnoreCase(“save-a-lot-slider”)) {
String articleId = journalArticle.getArticleId();
boolean articleApproved = journalArticle.getApproved();
if (articleApproved) {
JournalArticle article = JournalArticleLocalServiceUtil.getArticle(Long.parseLong(saveALotGroupId), articleId);
String image = JournalContentUtil.getValue(article, “image”);
String imageAltText = JournalContentUtil.getValue(article, “image-alt-text”);
String imageLink = JournalContentUtil.getValue(article, “image-link”);
String imageLinkWindow = JournalContentUtil.getValue(article, “image-link-window”);
String order = JournalContentUtil.getValue(article, “order”);
banner = new SaveALotHomepageBanners();
banner.setImage(image);
banner.setImageAltText(imageAltText);
banner.setImageLink(imageLink);
banner.setImageLinkWindow(imageLinkWindow);
banner.setOrder(order);
bannerList.add(banner);
}
}
}
Here is the SaveALotHomepageBanners class:
[CODE]
public class SaveALotHomepageBanners {
String image = null;
String imageAltText = null;
String imageLink = null;
String imageLinkWindow = null;
String order = null;
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getImageAltText() {
return imageAltText;
}
public void setImageAltText(String imageAltText) {
this.imageAltText = imageAltText;
}
public String getImageLink() {
return imageLink;
}
public void setImageLink(String imageLink) {
this.imageLink = imageLink;
}
public String getImageLinkWindow() {
return imageLinkWindow;
}
public void setImageLinkWindow(String imageLinkWindow) {
this.imageLinkWindow = imageLinkWindow;
}
public String getOrder() {
return order;
}
public void setOrder(String order) {
this.order = order;
}
}
I need to sort that items in the arraylist based on the “order” field in the SaveALotHomepageBanners object.
Thanks!