Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to remove an array of elements in a list in java?
    primarykey
    data
    text
    <p>Here is my codings:</p> <pre><code>package Controls; // Other code protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().write("&lt;h5 class='searchResultFramePara'&gt;Assigned roles&lt;/h5&gt;"); String[] Removelist = request.getParameterValues("deleterolelist"); //String[] Removelist=removelist.split(","); //System.out.println(Removelist); String username = request.getParameter("name"); //System.out.println(username); List&lt;String&gt; Removelist1 = new ArrayList&lt;String&gt;(); Connection Con = null; Statement st = null; ResultSet rs; int rs1; try { Con = LoginSrv1.getConnection(); st = Con.createStatement(); String roles_query = "SELECT ROLE_NAME FROM demo.ZMM_USER_GROUP WHERE USER_NAME = '" + username + "';"; rs = st.executeQuery(roles_query); while (rs.next()) { String assigned_role = rs.getString("ROLE_NAME"); String[] assigned_array = assigned_role.split(","); if (assigned_array != null) { for (int i = 0; i &lt; assigned_array.length; i++) { Removelist1.add(assigned_array[i]); } } } for (int j = 0; j &lt; Removelist.length; j++) { if (Removelist1.contains(Removelist[j])) { Removelist1.remove(Removelist[j]); } } System.out.println(Removelist1); StringBuilder b = new StringBuilder(); for (String text1 : Removelist1) { b.append(text1).append(","); } String Roletext = b.toString().replaceAll(",$", ""); System.out.println(Roletext); String update_query = "UPDATE DEMO.ZMM_USER_GROUP SET ROLE_NAME='" + Roletext + "' WHERE USER_NAME = '" + username + "';"; rs1 = st.executeUpdate(update_query); String assignedrole_query = "SELECT ROLE_NAME FROM demo.ZMM_USER_GROUP WHERE USER_NAME = '" + username + "';"; rs = st.executeQuery(assignedrole_query); while (rs.next()) { String rolename = rs.getString("ROLE_NAME"); String[] sarr = rolename.split(","); for (int i = 0; i &lt; sarr.length; i++) { //System.out.println("array"+i+sarr[i]); response.getWriter().write("&lt;a href='javascript:void(0);' id=" + sarr[i] + " class='availalbe' onclick='removelist(\"" + sarr[i] + "\");'&gt;" + sarr[i] + "&lt;/a&gt;&lt;br&gt;"); } } } catch (Exception e) { System.out.println(e); } } </code></pre> <p>here i get the Removelist array and rolename as a request from ajax. now i remove the removelist in Removelist1 list. for example i send Removelist having one string value "initiator",then it will remove. But for example it contains "initiator","productionmanager",(i.e., the array contains more than one value),then it will not remove it.pls help me.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload