Loop creating strings

i want to create 50 strings named str1 to str50. Do I have to write them all out or is there a way to loop construcing them?

If you need to associate names with strings, use a Map.
If you don't need to associate names with them (so you'll just refer to the bunch) you can use an array or a java.util.Set or a java.util.List.
Now you have to decide whether the strings will be in any order, or if duplicates are allowed.
If you don't need to order the unnamed strings and you want to discard duplicates, use a Set. It won't matter how many strings the user may input.
If you want the strings to have an order and not have duplicates, use an array or a List.
If you know at compile time how many strings there will be, you can use either an array or a List.
If you don't know at compile time, but at run time you know how many strings there will be before you ask the user to input them, you can still use an array or a List.
But if you don't know how many strings there will be until the user has stopped inputting them, and you need the strings in an order, use a List.

Similar Messages

  • Infinite loop creating new page due to column header overflow.

    i am getting an error and some pages "Infinite loop creating new page due to column header overflow. " --
    using report builder 9, i have a fairly simple report - that contains 4 subreports.
    for some pages i get the error - it seems if there is more data than would fit on 1 page.
    smaller pages work fine.
    the subreports are all simple queries and dumps....
    containing page header, column header, detail sections.
    page header has just a text bar of the name of the section.
    column header has the field names
    detail section has the data - 1 row for each row in the recordset.
    nothing i do seems to change getting "Infinite loop creating new page due to column header overflow. " on a page with more than 15-20 records returned.
    any ideas would be appreciated.

    Try these links if you are still having the issue:
    http://community.jaspersoft.com/questions/543302/receive-infinite-loop-creating-new-page-d ue-column-header-overflow-exception
    http://community.jaspersoft.com/questions/500177/infinite-loop-due-page-header-overflow

  • Creating String frm new String(charBuffer.array()) Vs charBuffer.toString()

    Whats the difference in creating String from CharBuffer by using array and by using toString() ?
    When ever i have some UTF-8 chars in my file (""someFile"), String created from new String( charBuffer.array()) appends some extra null/junk charaters at the very end of the file.
    How ever when i try charBuffer.toString() its working fine.
    For simple ASCII i.e ISO-*** charset both methods are working fine.
    Please see below code for reproducing. Here "someFile" is any text file with some UTF-8 characters.
    public char[] getCharArray()
    throws IOException
    Charset charset = Charset.forName("UTF-8");
    CharsetDecoder decoder = charset.newDecoder();
    FileInputStream fis = new FileInputStream("someFile");
    FileChannel channel = fis.getChannel();
    int size = (int) channel.size();
    MappedByteBuffer mbb = channel.map(FileChannel.MapMode.READ_ONLY, 0 , size);
    CharBuffer cb = decoder.decode(mbb);
    channel.close();
    fis.close();
    return cb.array();
    public String getAsString()
    throws IOException
    Charset charset = Charset.forName("UTF-8");
    CharsetDecoder decoder = charset.newDecoder();
    FileInputStream fis = new FileInputStream("someFile");
    FileChannel channel = fis.getChannel();
    int size = (int) channel.size();
    MappedByteBuffer mbb = channel.map(FileChannel.MapMode.READ_ONLY, 0 , size);
    CharBuffer cb = decoder.decode(mbb);
    channel.close();
    fis.close();
    return cb.toString();
    String fromToString = getAsString();
    String fromCharArray = new String(getCharArray());

    Whats the difference in creating String from CharBuffer by using array and by using toString() ?array() returns the entire backing array regardless of offset and position. toString() takes those into account.
    When ever i have some UTF-8 chars in my file (""someFile"), String created from new String( charBuffer.array()) appends some extra null/junk charaters at the very end of the file.More probably you haven't filled the array.
    How ever when i try charBuffer.toString() its working fine.So there you go.

  • Read text from file, created string, but don't know how to split string.

    I've been busy with a little application which should be able to save a (2d) array to a text file, and open it afterwards.
    I already completed both steps, but i'm stuck at the reading part.
    I'm not familiar with the load function, so i used Datainputstream, which i've converted to a String afterwards. The systemconsole shows the correct information when I put the string to the console, but now i want to split the string.
    For example, my console writes:
    FILE CONTENT=458,304,0,345,432
    ("FILE CONTENT=" has been manually added to the system.out)
    Because im not English, and i don't know what I should search for on the web in order to find this, i've come up here and created this post.
    I've got an object array which is 2-dimensional, and now i was wondering how i could "rebuild" my array array[x][c] in which the first number of my file content should be X and the other numbers should be put in [c].
    Offcourse, the ',' should be skipped.
    I do have read things about tokenizing and so on, but i think that every single letter is read then.
    Any help would be much appreciated.

    Ok, thanks for the reply.
    I feel a bit ashamed now, because my topic title contains the function i needed...
    So, assuming that i would have
    String content = "458,304,0,345,432";i could split this and put this in an array string using a code like
    String[] arry = null;
    array = content.split("\\.");I haven't tested the code yet, cause i'll go to bed soon, but will this split all at once and put it in the array or do i have to create a loop or something ?
    And is it possible to put number one using split in the array[x][v] on the x location and the others at the [v] location ? (the first number of each five has to be added to [x] and the other 4 to [v] )
    Again thanks for your reply, cause im a bit further this way in accomplishing what i want to reach :)

  • New Apple Loop Created at Wrong BPM?

    Hi,
    I've beat mapped an audio region, which adjusted the project tempo to about 122.5 BPM, which is the correct value.
    I've trimmed the region to an even number of bars, and exported it as an Apple Loop as I have always done in the past.
    However, when I go to open it up in the media browser, it says the BPM is 95, which is wrong. When I make it follow the tempo of another project which is also around 122.5, it makes it way too fast (it over-compensates since it thinks the loop is at 95BPM). I've tried it in the Apple Loops utility, and the same thing happens.
    Any help is very much appreciated!

    Set the permissions on the other volume's root directory the same as the boot volume.
    owner:root
    group:admin
    chmod 1775
    Make a /Users directory on the other volume and
    set permissions same as on the boot volume,
    owner:root
    group:admin
    chmod 755
    create your new user directory in the /Users directory on the other volume.

  • Efficient looping over strings

    ABAPers,
    I need to loop over all the characters in a string. Here is the pseudo code:
    data: myData TYPE string.
    data: n TYPE i.
    data: ch TYPE char1.
    n = STRLEN( myData).
    DO n TIMES.
      ch = myData(sy-index).
    ENDDO.
    While this code would work, the problem is that I am actually iterating over myData two times. STRLEN itself is internally iterating over myData to compute the length.
    Is there a more efficient looping mechanism without going through STRLEN?
    Thank you in advance for your help.
    Pradeep

    Hi,
    You can try this when it comes to converting things
        WHILE myData IS NOT INITIAL.
    do something
        ENDIF.
        myData = myData+1(*).
    Eddy
    PS.
    Put yourself on the SDN world map (http://sdn.idizaai.be/sdn_world/sdn_world.html) and earn 25 points.
    Spread the wor(l)d!

  • Textarea - create String that acts like a single character

    Hi guys,
    I am trying to create a string in a textarea that acts like a single character. By this, I mean that the user cannot edit the contents of that section of text. Here's an example:
    Textarea text:
    [Number of Iterations] * 35 / 200
    I want the [Number of Iterations] to be read-only. In addition, if the user tries to delete the beginning or end of [Number of Iterations], the whole thing is deleted. If possible, I would like cursor operations to treat it like a single character as well (i.e. to go from |[Number of Iterations] to [Number of Iterations]| takes a single right button press).
    Some commercial applications like Microsoft Word do this with Automatically created text in documents (like page numbers and date stamps) and I was wondering if I could do the same thing using a Textarea.
    Any help would be greatly appreciated.
    Thanks in advance,
    Steve

    A JTextPane allows you to add components to the text pane. So you might be able to create a JLabel with your desired text and insert the label into the text pane.

  • Create String from all Collection Items

    Hi all, I've been using Project Siena for the last week and I'm having a lot of fun with it.
    Right now, I'm having a problem creating a string comprised of all the rows of a particular collection.
    I am trying to generate the string for an email body. So far I have a 1 column collection called EmailCollection. It consists of rows of text with the appropriate URL Encoded characters. I would like to be able to export all the rows of this
    collection to a string, and then add this string into the Launch(mailto:) body variable.
    Let me know if I'm not being clear with this, and thanks for any help in advance!
    Elliot

    Thanks for the reply, StonyArc. I actually used your original thread to get me started until I ran into problems with exporting the entire single column collection to a concatenated string. I found a way to get it working, though it's not an elegant solution
    and it wont work if the number of rows in the collection changes.
    I'll try to explain it here, and if anyone else can think of a better way, I'd like to try it :)
    I needed to create an URL encoded string for my emails which consisted of the relevant pricing information from a Collection with 8 rows called NewPricingCollection. 
    Collect(EmailPricing, Substitute(Substitute(Substitute(Concatenate(NewPricingCollection!SetupItem,": ", NewPricingCollection!NewAmount, " ", NewPricingCollection!UnitType, "s ($", NewPricingCollection!TotalPrice, ")"), " ", "%20"), "$", "%24"), ":", "%3A"));
    This created a single column collection with 8 rows which looked like this: SetupItem: 5 Units ($TotalPrice). I used the substitute function to replace the non-URL friendly characters with their encoded equivalents. I'm not sure if this is the best
    practice use of the Substitute function by the way.
    Once I had the Single Column Collection, I couldn't find a way to concatenate the contents of each row into a single string. I was able to use the Lookup function to retrieve the first row of the collection, but that was it. Note that I may be using the
    lookup function incorrectly too :)
    I ended up using Last and LastN Functions to retrieve the specified number of rows from the end of the collection. Then I used the Lookup function to retrieve the string from the first row of each retrieved collection, then concatenated it together as a
    single string - along with the rest of the email body.
    LookUp(EmailPricing, Result in EmailPricing, Result) & "%0A" & LookUp(LastN(EmailPricing,7), Result in EmailPricing, Result) & "%0A" & LookUp(LastN(EmailPricing,6), Result in EmailPricing, Result) & "%0A" & LookUp(LastN(EmailPricing,5), Result in EmailPricing, Result) & "%0A" & LookUp(LastN(EmailPricing,4), Result in EmailPricing, Result) & "%0A" & LookUp(LastN(EmailPricing,3), Result in EmailPricing, Result) & "%0A" & LookUp(LastN(EmailPricing,2), Result in EmailPricing, Result) & "%0A" & LookUp(LastN(EmailPricing,1), Result in EmailPricing, Result)
    This created a string that looked like this inside of an email body:
    SetupItem1: 5 Units ($TotalPrice)
    SetupItem2: 5 Units ($TotalPrice)
    SetupItem3: 5 Units ($TotalPrice)
    SetupItem4: 5 Units ($TotalPrice)
    SetupItem5: 5 Units ($TotalPrice)
    SetupItem6: 5 Units ($TotalPrice)
    SetupItem7: 5 Units ($TotalPrice)
    SetupItem8: 5 Units ($TotalPrice)
    As you can see it will only work correctly with a collection of 8 rows, so if the number of items changes, then I'll need to find a better solution. 

  • Creating string array constant

    Hey, this is probably a stupid question but I am still trying to figure out everything in LabVIEW. Is there a way to create an array constant that holds strings? I know you can define an numerical array constant but can you also do one for strings, or do I just have to pass multiple text fields into a "build array" function.
    Thanks,
    Paul

    Another tip:
    Many times, you already have a function on the diagram that expects an array of strings (or whatever you specifically need), so the easiest is to right-click the connector and select "create constant". You will get an diagram constant of the default type for that input or output terminal.
    LabVIEW Champion . Do more with less code and in less time .

  • Creating string pointer for dll

    I'm trying to use a DLL to access a Reflective memory board using LV6.i
    under Windows2000. The first call to the DLL takes a pointer to a string
    that contains the device name and it returns a handle to that has to be
    used in all other calls.
    The syntax is - RFMHANDLE rfmOpen( char devPath );
    The example in the documentation is;
    RFMHANDLE rh;
    char *devPath = "\\\\.\\RFM1"; This is the
    W2000 name for the board
    if( (rh = rfmOpen( devPath ) ) == NULL ){
    exit(1);
    All the other calls pass the handle rh as the calling parameter.
    My question is how do I create the string pointer devPath?
    Ed

    Ed,
    I'm a Labview DLL rookie but I think all you have to do is in the DLL
    configure define the arg Type as a "String" and the String Format as a "C
    String Pointer". Then when you wire that terminal up, just connect it to
    Sting Constant or Control. Then just pass that argument the device name
    string. Labview will take care of actually passing the that string pointer
    value to the DLL.
    I just done something similar with an array of 16 bytes. I am supposed to
    pass the function the pointer to the array and it will change the data in
    that array. I defined the arg as Type "Array" of Data Type "Unsigned 8-bit
    Integer", Dimension "1", and Array Format as an "Array Data Pointer". I
    then connected that terminal to the Build Array function of 16 bytes. The
    output terminal
    directly accross from that input terminal was connected to
    an array indicator. When I run the VI the data bytes were changed as
    expected.
    The point is that I never really had to deal with the pointer directly. So
    you don't have to create the string pointer, just create the string and
    connect it to the terminal defined as a string.
    - David
    Ed Bogart wrote:
    > I'm trying to use a DLL to access a Reflective memory board using LV6.i
    > under Windows2000. The first call to the DLL takes a pointer to a string
    > that contains the device name and it returns a handle to that has to be
    > used in all other calls.
    >
    > The syntax is - RFMHANDLE rfmOpen( char devPath );
    >
    > The example in the documentation is;
    > RFMHANDLE rh;
    > char *devPath = "\\\\.\\RFM1"; This is the
    > W2000 name for the board
    >
    > if( (rh = rfmOpen( devPath ) ) == NULL ){
    > ....
    > exit(1);
    > }
    >
    > All the other calls pass the handle rh as the calling paramete
    r.
    >
    > My question is how do I create the string pointer devPath?
    >
    > Ed

  • Why r we allowed to create String objects with & without using new operator

    While creating any object, usage of the new operator is a must...but only for the string object we can create it with and also without new operator how is it possible to create an object without using new operator.

    Because Mr. (Dr.?) Gosling is a kindly soul who realizes that programmers have deadlines and, when he designed Java, was not so rigid or unbending as not to realize that from time to time, certain shortcuts are warranted, even in a relatively pure language such as Java. The direct String literal assignments are a shortcut over using the new operator making Java programming (and execution; there's also a performance benefit) more streamlined.
    So look not the gift horse in the mouth, but simply bask in the simplification and ease on the eyes and directly assign your little literals to your heart's content.

  • Createing string objects

    String s= new String("abc");
    String s1="abc";Is there any performence issue between these two?
    I think both will take same time to create objects.

    Yes, there is a performance implication.
    When using the first line String s = new String("abc"); you are actually creating two objects. As a general rule, you should never use a String class constructor when initializing to a literal value. Even doing String s = new String("abc" + someVariable) is creating one more object than needed. "abc" is the firs object, the result of "abc" + someVariable is the second object, and the String created by the constructor is the third.
    It should be noted most recent JVMs use some level of caching of String Literal value objects (I believe this goes as far back as JDK 1.3), such that "abc" is only be created once by the JVM (though I'm not sure if it will cache all literal String objects or use some type of LRU algorthm to discard some of them). Regardless, there is some level of efficiency you get from the JVM doing this. Thus if a method containing String s = "abc" is called repeatedly, a reference to the same String object should be used everytime; there will be no further creations of the object as long as the JVM keeps it in cache.
    Using String s= new String("abc") will leverage the cached literal reference to "abc", but also creates a new instance of String to refer to the literal everytime your method is called. This is much less efficient.
    Run the following code (I did it using JDK 6):
    package org.einsteinium.samples;
    public class StringTest {
         public static void main(String[] args) {
              String s1 = "abc";
              String s2 = "abc";
              boolean equalMethodTest = s1.equals(s2);
              System.out.println("Are the objects the same using the equals method? " + equalMethodTest);
              boolean equalOperatorTest = (s1 == s2);
              System.out.println("Are the objects the same using the equal operator? " + equalOperatorTest);
    }It will print:
    Are the objects the same using the equals method? true
    Are the objects the same using the equal operator? trueNow if you re-write it to:
    package org.einsteinium.samples;
    public class StringTest {
         public static void main(String[] args) {
              String s1 = new String("abc");
              String s2 = "abc";
              boolean equalMethodTest = s1.equals(s2);
              System.out.println("Are the objects the same using the equals method? " + equalMethodTest);
              boolean equalOperatorTest = (s1 == s2);
              System.out.println("Are the objects the same using the equal operator? " + equalOperatorTest);
    }it will print:
    Are the objects the same using the equals method? true
    Are the objects the same using the equal operator? falseI hope this helps some.

  • Looping through string tokenizer

    Hi pple...
    I am doing a project in jsp...i have some pblm in a form that contains string tokenizer method..let me make u all very clear..
    Ex:in my databse i have stored country as us|uk|uae|india..
    so wat my requirement is once i login,depending upon my id it should check the country..if the login id has one country den no pblm i can easily check a condition and i will divert the page..if the loginid has two countrys what should i do..
    i have made the foll code snippet:
    log_country=rs.getstring();database values(i.e...pipe separated country)
    string tokenizer st=new stringtokenizer(log_country,"|");
    while (st.hasMoreTokens())
         i=0;
         st=st1.nextToken();
         i++;
    for(i=0;i<st.length;i++)
         if(st[i].equals("null"))
              st[i]="";
              else
              out.println(""+st[i]);
    for(i=0;i<st.length;i++)
    if(st[i].equals("us"))
    {%>
    <jsp:forward page="admin2.jsp" />
    <%}
    if the st array contains two countrys how can i get the values ...
    st[0]>>for us
    st[1]>>for uk..i hav assumed ,,but it never works
    how can i get to know these two countrys and i want to forward to one page..thanks in advance

    Friend use code tag to post your code.
    Design like below will work
    String log_country = "";
        try {
            log_country = rs.getString("Countrys");    // database values (i.e...pipe separated country)
        } catch (Exception e) {
        String[] countrys = log_country.split("[|]");   
        for(int i=0; i<countrys.length; i++){
            if(countrys==null || countrys[i].equals("null") || countrys[i].trim().length()==0){
    out.println("No Country"); // do whatever
    } else{
    out.println(countrys[i]); // do whatever

  • Need to create String Formated XML

    hi all,
    i have a requriment where i need to send the reuslt after a database search in a form of string but in a formated value.
    e.g.
    <message>
    <type1>
    <attr1>123 </attr>
    </type1>
    <type1>
    <attr1>123 </attr>
    </type1>
    </message>
    something lilke this.
    insted of hardcoading the stuffs how can i do?
    please help

    You have some data and you want to output an XML document that contains that data? Then a SAX filter is a good choice. Start here:
    http://www.cafeconleche.org/books/xmljava/chapters/ch08s05.html

  • Why does this loop create a 3D array instead of a 2D?

    Hi,
    This should be a relatively simple question. I am feeding a 1-D array (1 x 801) in a loop into a build array function and looping it back on itself to build the array. I am rather confused as to why this is producing a 3D array, can someone explain why?
    Thank you,
    Michael
    Attachments:
    QCM.vi ‏113 KB

    Where are you seeing the 3D array? If it is at the far right of the diagram, at the edge of the FOR loop, it is because you have the autoindexing set, which is going to make a 1D array of your 2D array data, a 3D array. As the two sub-vi's didn't come with your vi I don't know what the one with the "17" as an input does, nor what the other one does either, other than apparently produce two 1D arrays.
    Putnam
    Certified LabVIEW Developer
    Senior Test Engineer
    Currently using LV 6.1-LabVIEW 2012, RT8.5
    LabVIEW Champion

Maybe you are looking for

  • Update bootcamp on macbook pro 15 mid 2010

    Hy there, my friend has a macbook pro 15inch mid 2010 with OS X 10.8.2 and he wants to install windows 7  from an image. There is bootcamp 5.0.0 installed. Isn´t it possible to create a bootable windows 7 usb stick with bootcamp? I didn´t found an up

  • How can you get out of a group text

    How can you stop a group message text?

  • Set-up Vendor rebates in SAP

    Hi SAP Gurus, Good day! Please help. How will I Set-up Vendor Rebates in SAP? Currently, we are getting rebates from our Vendors based from the total sales of an item or based from the total purchased amount/quantity in a given period. How will I inc

  • Acrobat Ignore "Set as default PDF Viewer" Setting

    Hello, I see from previous posts that this has been an issue for a while. I have an image that contains Adobe Reader. That image is deployed to all users. Some users get Acrobat Pro. also. So I went thru the whole customization tool and selelcted "Ma

  • SalesForce XI Integration...

    Hi,    We are trying SalesForce-XI Integration using WSDLs. We are facing the following issues:   a. The SalesForce SOAP Calls require a session id string to be passed as part of the SOAP header. This soap header is not visible as part of the message