Adding parentheses to each item in HashSet

Dear All,
Having almost completed my first java tool which queries a database to allow user-defined filtering, I'm running into a last 'small' problem:
I won't bore you guys with the whole thing, but instead will just focus on the part where i'm stuck, in the hope that somebody can give me a useful tip as to how to solve this! Thanks very much in advance for any input!
Basically, what it comes down to is that I query the database twice, resulting in two lists of data stored as HashSets in Java, to then work out the intersect of them both with the listI.retainAll(listII) function. Finally, I want to use the merged list to query the database again, using the variables listed in the final set. In order to use the list in the query, I first convert the HashSet to a string as follows:
String convList = listI.toString();As this results in a string with square brackets [] and mySQL needs regular brackets, I convert them like this:
convList = convList.replace('[', '(');
convList = convList.replace(']', ')');This will result in something along the lines as (result1, result2, result3, result4, etc.). The problem is though, that I would need it to be like
("result1", "result2", "result3", "result4") in order for mySQL to accept it using the IN clause.
I tried to add the parentheses using:
convList = convList.replaceAll(',', '",');
        convList = convList.replaceAll(' ', ' "');but the Java compiler complains of an error with "unclosed character literal", so I was hoping somebody could maybe give me a hint as to how I can add parentheses for each member in the list? Thanks alot in advance

les_paulde wrote:
wow, thanks for your swift reply! This definitely solved my problem and I can now run the query. The code turned out as follows:
String convList = listI.toString();
convList = convList.replace("[", "(\"");
convList = convList.replace("]", "\")");
convList = convList.replaceAll(",", "\",");
convList = convList.replaceAll(" ", " \"");
And what happens if the String representation of the object in your list contains one of the characters you're replacing? It will go awfully wrong!
This is safer:
public static String asString(List<?> list) {
    StringBuilder b = new StringBuilder();
    b.append('(');
    for(int i = 0; i < list.size(); i++) {
        b.append('"').append(list.get(i)).append('"');
        if(i < list.size()-1) b.append(", ");
    return b.append(')').toString();
System.out.println(asString(listI));

Similar Messages

  • Chart legend : adding tooltip on each item

    Hi,
    My app displays a simple Linechart and its legend. I'm
    surprised to see that the Legend component doesn't provide many
    possibilities in accessing each of the items that compose it.
    First, I'd like to add a tooltip on each item of the legend.
    Then I would like to display a checkbox in front of every marker,
    to display/hide the corresponding item in the Linechart.
    One way could be to extend the Legend item (about this I
    found
    this
    nice - yet complicated - example), but I'd really like to know
    if there is a more simpe way to achieve it. As the Legend component
    is very dependant from its dataprovider, maybe I'd rather create my
    own custom legend, using my chart's values ?
    Any help will be appreciated ! Popop ./.

    les_paulde wrote:
    wow, thanks for your swift reply! This definitely solved my problem and I can now run the query. The code turned out as follows:
    String convList = listI.toString();
    convList = convList.replace("[", "(\"");
    convList = convList.replace("]", "\")");
    convList = convList.replaceAll(",", "\",");
    convList = convList.replaceAll(" ", " \"");
    And what happens if the String representation of the object in your list contains one of the characters you're replacing? It will go awfully wrong!
    This is safer:
    public static String asString(List<?> list) {
        StringBuilder b = new StringBuilder();
        b.append('(');
        for(int i = 0; i < list.size(); i++) {
            b.append('"').append(list.get(i)).append('"');
            if(i < list.size()-1) b.append(", ");
        return b.append(')').toString();
    System.out.println(asString(listI));

  • Adding user review comments to each item

    I am creating my site in Muse and then will be publishing to BC. My website will be have a least 7,000 items on it. I want to be able to have user review comments for EACH item. will I be able to do this using BC? I am guessing every item would have to have it's own page and then a module added to it. I am looking at adding 7,000 modules unless there is a faster way. Thank's in advance all

    Yes. Please have a look at the following article about the comments module http://kb.worldsecuresystems.com/758/bc_758.html
    Also, you can integrate Facebook comments as per http://kb.worldsecuresystems.com/851/cpsid_85118.html

  • How to create a background image for each item in a List object

    Hello.
    I am trying to create a background image that displays whenever a user posts something to a list.  For example when a user posts text it would appear in a list.  The new item in the list would contain a specific background image with the users text appearing on top of the background image.  I do not want a background image for the entire list, rather each item within the list.
    I am not sure how clear this is so I added an image below.  When a user enters text in and clicks the "post-it" button their text would appear below with the sticky note background. 
    I am not sure which list type would be best for this problem or how to create insert the image, so I am open to suggestions. 
    Thank you for your help.  Any advice or guidance will be greatly appreciated!

    Hi
    the easiest way would be with itemRenderer.
    You have to do two things:
    1. In your list declaration use a item renderer: <mx:List itemRenderer="myRenderer"/>
    2. create a flex component myRenderer that will be the single item. This can be a canvas with a background image and a text field on it.
    When you add a new item to the list, a new myRenderer item will be created and the data property will be passed to it. So you have to put "data" in your textField.
    If you need more help try looking at Tour de Flex samples, they're pretty easy.
    Andrei

  • Each item in the delivery should have separate invoice

    HI friends,
    who to do separated invoice for each item of the delivery, even if the bill to party and billing dates are same.
    thanks
    nitchel

    Hi,
    Rather than block individual items manually each time an invoice is raised, a copy control routine can be written in which you can modify item level split criteria which is explained below in detail.
    In VOFM transaction, go to 'Data Transfer' and choose 'Billing Documents'. You can see a list of routines which can be used in copy control configuration. Define a new routine in this list (501 for example).
    Copy the piece of code from routine 001 (include FV60C001) to this new routine and add another field 'POSNR' to the structure ZUK. Copy delivery item number to ZUK-POSNR (ZUK-POSNR = LIPS-POSNR) before ZUK gets assigned to VBRK-ZUKRI.
    Then assign this routine in the item level copy control of delivery to billing of the respective document types. This will ensure that as many invoices get generated as there are delivery items.
    But before that, decide the scope for this invoice split, i.e. for what document types / organizational units, etc. this is required. These checks may be added as initial conditions in the routine before LIPS-POSNR is copied to ZUK.
    Cheers,
    KC
    PS: I had earlier tried some other split criteria which worked fine. If this doesn't work as it is described above, you may have to do minor fine tuning but the idea of splitting invoices by tweaking ZUKRI will certainly work.

  • Used pictures not added to the calendar items ...

    Hi ...  Why aren't the pictures used to create the calendar not added to the calendar items (in parenthesis) ?

    Hi ...  Why aren't the pictures used to create the calendar not added to the calendar items (in parenthesis) ?

  • Color for each item ring

    Hello,
    Is it possible to assign a different color for each item in a ring control ? See what I start in attached file.
    Thanks
    Attachments:
    enumeration_avec_couleur.vi ‏8 KB

    Attached is the LV 8.0 version.  I also added a control as described by Evan because I hadn't thought of it originally, but it is probably the best option -- it places text on color and doesn't require a loop to update.
    David C
    Applications Engineering
    Attachments:
    enumeration_avec_couleur2.vi ‏74 KB
    Control 2.ctl ‏6 KB

  • UWL Removing detail area menu/context menu that appears on each item/task

    Hi
    On the MSS Universal Worklist on the Portal(EP7 SP14)(ESS MSS 600 SP11, ECC 6), how can I remove the context menu(detail area menu) on each item/task. The options for the menu are Forward and Resubmit.
    I understand(I stand corrected) that it is on uwl.standard xml file where this menu can be removed. Im not too sure what to change on this file.
    Your help is much appreciated and points will be rewarded if your answer works.
    Kind regards
    RD

    Hi Andy
    Thank you for your quick response. I have added the necessary actions to the "List of UWL Actions to exclude" property, and this sorted out my problem.
    Thank you - I have given you points
    Cheers
    RD

  • When I try to use autofil to enter my name address ect it requires me to click on each item , name, email ect how do I get it to use the whole profile

    when I right click on autofil a widow comes up with my profiles, I see no way to simply choose one and have all the info filled in. I have to click each item, name , address ect to have it show on whatever form I am trying to fill

    You can try one of the form fill extension:
    *Autofill Forms: https://addons.mozilla.org/firefox/addon/4775
    *Autofill: https://addons.mozilla.org/firefox/addon/262804/
    *fireform: https://addons.mozilla.org/firefox/addon/3193
    *Formito ( Form Filler ): https://addons.mozilla.org/firefox/addon/formito-form-filler/

  • The operation can't be completed because some items had to be skipped. For each item, choose File Get Info, make sure "Locked" is deselected, and then check t

    The following error comes up when I try to install the updated Firefox:
    "The operation can’t be completed because some items had to be skipped. For each item, choose File > Get Info, make sure “Locked” is deselected, and then check the Sharing & Permissions section. When you are sure the items are unlocked and not designated as Read Only or No Access, try again."
    When I follow the instructions in the error message, it shows that my user name has read and write access. There are a couple other items that are read only. I tried to change this to read and write, but the Sharing and Permissions options are greyed out and will not let me change them. What is the work around for this? I would really like to install the new firefox.
    Thanks.

    Hello,
    Certain Firefox problems can be solved by performing a ''Clean reinstall''. This means you remove Firefox program files and then reinstall Firefox. Please follow these steps:
    '''Note:''' You might want to print these steps or view them in another browser.
    #Download the latest Desktop version of Firefox from http://www.mozilla.org and save the setup file to your computer.
    #After the download finishes, close all Firefox windows (click Exit from the Firefox or File menu).
    #Delete the Firefox installation folder, which is located in one of these locations, by default('''This will NOT delete profile info such as bookmarks and history'''):
    #*'''Windows:'''
    #**C:\Program Files\Mozilla Firefox
    #**C:\Program Files (x86)\Mozilla Firefox
    #*'''Mac:''' Delete Firefox from the Applications folder.
    #*'''Linux:''' If you installed Firefox with the distro-based package manager, you should use the same way to uninstall it - see [[Installing Firefox on Linux]]. If you downloaded and installed the binary package from the [http://www.mozilla.org/firefox#desktop Firefox download page], simply remove the folder ''firefox'' in your home directory.
    #Now, go ahead and reinstall Firefox:
    ##Double-click the downloaded installation file and go through the steps of the installation wizard.
    ##Once the wizard is finished, choose to directly open Firefox after clicking the Finish button.
    Please report back to see if this helped you!
    Thank you.

  • F110 - each item in each payment document for the same vendor

    Hi Guru,
    When i use F110 to do auto payment run for one vendor, each item is paid by each payment document although the document currency is the same, do you know why it appear like this, by right, all the vendor open items should be paid in one payment document, what is the possibility for this scenario, how to check it.
    thanks,
    Kick

    There are things that you should check which may be causing this:
    (1) In the vendor master (FK03) go to the section "Payment Transactions Accounting" and see whether the box "Individual Pmnt" has been selected. If it has, then deselect it.
    (2) In transaction FBZP go to the "Payment Methods in Company Code" section, double click on the relevant payment method, and check whether the box "Single Payment for marked item" has been selected. If so, deselect it.

  • Can you calculate multiple text boxes to achieve a total value?  If so how is that done?  I am trying to create a order form where multiple items can be purchased but i would like the values of each item to calculate so I can achieve a total value.

    Can you calculate multiple text boxes to achieve a total value?  If so how is that done?  I am trying to create a order form where multiple items can be purchased but i would like the values of each item to calculate so I can achieve a total value.

    Hi sashby51,
    I've moved your discussion to the PDF Forms forum--the folks who visit this forum regularly should be able to point you in the right direction.
    Best,
    Sara

  • How to find out userid of purchase requisition at each item level

    for a particular requisition at each item is released by a some user, how to find out these user name.
    ex.
    pur.requi     pur req item    ueser_id
    10092188    00001            ?
    10092188    00002            ?
    10092188    00003            ?
    10092188    00004            ?
    in the above data purchase requisition is same but purchase
    requisition items are different. in this i want to find out user
    id of releaser for each item of particul purchase requisition.

    dear friend
    in table
    there is group
    tabkle : eben
    field:    FRGGR
    you get it easily.
    rewards are expecting:
    vivek

  • BAPI_SALESORDER_CREATEFROMDAT2 with each item having diff Ship to party

    Hi Abapers,
    Can anyone guide me in this scenario:
    Creation of sales order using BAPI_SALESORDER_CREATEFROMDAT2 with each item having different ship to party.
    Ex :
             Item Material Qty Delivery date Ship to party
             10   p-100     2     24.12.2011    1020
             20   p-100     4     26.12.2011    1050.
    Can we use this bapi for the present scenario. If yes how to send the multiple ship to party. when i create sales order through VA01 its getting created but not with this bapi.
    Thanks for supporting.

    Pass Table ORDER_PARTNERS with
    PARTN_ROLE
    PARTN_NUMB
    ITM_NUMBER   = '000010'  
    PARTN_ROLE
    PARTN_NUMB
    ITM_NUMBER   = '000020' 
    and so on

  • What's a simple data base to use? I want to include photos with each item (jewelry)..

    Okay, here's what I want to do. The wife's got at bunch of the wife's jewelry plus a few rare coins that need to go into the safety deposit box soon but before that, I need at least one photo of each item along with its details. This is the first time I've done something like this so it'll be a learning experience. I plan to get an iPad sometime in the next month but right now I'm just experimenting;  using a point and click camera and a notepad.  (Question, would my iPod Touch make this easier in any way?)
    Can you recommend a simple and inexpensive app that would make that process relatively painless? Until, the iPad arrives, my handwritten notes will go onto a document on my MacBook Pro....?
    Anyway, there's got a be an easier way to do this.
    Looking forward to your thoughts.
    Brian
    PS: Apologies if this isn't the best community for this question. Apple's support options seem to have really changed since I was last here. Feel free to suggest other groups who could answer the above question better.

    There are several home inventory apps available in the app store. Many include the ability to add photos and most would probably work on the Touch as well as an iPad.

Maybe you are looking for