Home » Jquery » javascript – How to get specific items from arraylist? I need to iterate my list based on logic

javascript – How to get specific items from arraylist? I need to iterate my list based on logic

Posted by: admin February 22, 2020 Leave a comment

Questions:

I am having list which has 20 to 25 messages. When my page is loaded all my messages are displayed. Now i am creating a button on same page. I want to filter few defined messages from that list. So once the page is loaded 15 messages are displayed. Rest messages from my list will be displayed on click of button. How can I implement this.Any help will be appreciated. Tried below code

Declared list which contains specific messages:

public final List<String> message = Arrays.asList(new String[] {message1,message2,message3,message4});

Below map contains all messages. Messages defined in above list is also present in map:

Map<String, List<String>> allmessageMap = (Map<String, List<String>>) request.getAttribute("allmessageMap");

For loop is used in JSP to iterate and display all string messages in map.
I am adding button in JSP. Need logic to seperate messages defined in list. Those messages sholuld not be displayed. Only display on click of button. Please help.

How to&Answer: