Instance a new String

hello guys
i have a statement like:
  "select * from myTable where name='NameX' and sex='SEX' and " it is generated by If statement,but how can i delete the " and " at the end of the statement and make the remain to be a new String instance.
thanks

String trimmedStr = str.substring(0,str.lastIndexOf(" and "));

Similar Messages

  • Creating new String using only specific set of chars from another String

    I've performance troubles doing this task:
    I have a very long String A (up to 1 million character length)
    This String contains different characters.
    I need to create a String B containing only specific characthers (with a defined character code)
    An example:
    String A: [80]='P' [65]='A' [71]='G' [69]='E'For example I want to extract only character 65 and 71
    String B: [65]='A' [71]='G'I already did the code to do this, (it's quite simple) but I think I have some very big performance issues, and I suppose I can do this task much more quickly!!
    String out = "";
              for (counter = 0; counter < text.length(); counter++) {
                   char currentchar = text.charAt(counter);
                   int currentvalue = (new Integer(currentchar)).intValue();
                   switch (currentvalue) {
                   case 65:
                        char[] newstring = new char[1];
                        newstring[0] = currentchar;
                        out += new String(newstring);
                        break;
                   case 71: //
                        break;
                   // other cases
                   default:
                        // nothing to do...
              }Can you suggest me something to improve the performances?
    Thank you!

    If you've got a number of characters in your acceptance set I'd use indexOf, and I'd probably use StringCharacterIterator. Mind you, with a million characters I'd probably not load them all at once anyway, but process them as streams.
    StringBuffer out = new StringBuffer(s.length() / 5); // allocate plenty
    StringCharacterIterator it = new StringCharacterIterator(s);
    for(char c = it.first(); c != CharacterIterator.DONE; c = it.next())
      if("AG".indexOf(c) >= 0)
          out.append(c);
    return c.toString();

  • Which is better and why a = new String("AA") or a = "AA"

    Hi,
    Which is better and why
    String a = new String("AA") or
    String a = "AA"
    Does invoking a construtor waste memory? Please explain in detail.
    Thanks in advance
    Deepak

    > So in case "AA" not there in string pool,
    That is not correct.
    does new creates "AA" on string pool as well as heap memory?Yes. The literal "AA" points to a pooled String object. The new operator creates a new String object with the same character sequence ("AA"). You can verify this with a little code...
    String s = new String("AA");
    assert s != "AA";
    assert s.equals("AA");
    assert s.intern() == "AA";~

  • 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.

  • What is this - Object[] x = {new String[]{"a","b"}};

    What is the meaning of this -
    Object[] x = {new String[]{"a","b"}};
    I have a function which takes Object[] as a argument. And I have data structure like this -
    Name = Zoolander
    Name = Hansel
    Name = Mugatu
    I am not interested in the Name part. This has to be converted to - Object[] x = {new String[]{"a","b"}}
    It works if I hard code the values like this -
    Object[] x = {new String[]{"Zoolander","Hansel","Mugatu"};
    Thanks in advance

    Don't crosspost, please.

  • Bpc  install issue : string reference not set to an instance of a string.

    hi
    i am trying to install BPC server in my machine . after giving bw credential i am getting below error
    bpc issue string reference not set to an instance of a string. parameter name s
    does any one came across this?  what might be wrong here?
    please help me

    Hi
    Once you install the ABAP and .NET components, the server manager would be part of your program list. It would be something like SAP->BPC Server 7.0. Click on the server manager and in the server menu you will find 'Diagnostic' option as this would give you a good picture about the installation success post installation.
    During the server manager installatio process, you would be alerted if any of the pre requisite software is not installed on your server machine. Please check the installation guide for detailed steps.
    Thanks,
    Santosh

  • Return all instances of a string value

    I know that similar questions have been asked before but I am having a tough time getting things to work.
    I would like to search for all instances of a string value (shown red) and return the corresponding values in the adjacent cells (shown green) so that each room number is represented.  For example, I want the search for "Adequately" to return rooms 236 and 237 (and 237 just once even though it is listed twice).  Is this possible?
    Any help is appreciated.
    Clay

    Here's an example, similar in some ways to Yvan's, but taken a bit further.
    Data table (left) contains only the original data. I've shortened the ratings to allow an easier fit on this page.
    Summary table does the work in two stages.
    Pulls the room numbers for rooms matching each rating. (yellow portion of table. If desired, these rows may be hidden.
    Builds a list of these for each condition. (Footer row)
    Formulas (all on Summary)
    Row 1 is a header row, and contains the Rating labels, which must match those used on the Data table.
    B2:   =IF(AND(Data :: $E2=B$1,COUNTIFS(Data :: $E$2:$E2,B$1,Data :: $C$2:$C2,Data :: $C2,Data::$B$2:$B2,Data :: $B2)=1)," "&Data :: $B2&" "&Data :: $C2&" ","")
    Fill right to column F. Fill down to row 16 (as many rows as there are data rows on Data)
    Note the " " at the beginning and end of the 'if true' part: " "&Data :: $B2&" "&Data :: $C2&" "
    There is a single space between each pair of quotation marks. These are necessary to the second formula below.
    Row 17 is a Footer row.
    B17:  
    =IF(COUNTA(B)-COUNTBLANK(B)=0,"",TRIM(SUBSTITUTE(CONCATENATE(B2,B3,B4,B5,B6,B7,B 8,B9,B10,B11,B12,B13,B14,B15,B16),"  ",",
    There is a return character in the formula immediately before the last quotation mark. Press option-return to enter a return into a formula.
    SUBSTITUTE finds the two spaces added between items in the list and replaces them with a comma followed by the return noted above.
    TRIM is used to remove the single space before the first item in the list and the single space after the last.
    Regards,
    Barry

  • Migration of older version of composite instances to newer version

    hi,
    i need to migrate the older version of composite instances to new version.
    i have deployed a BPEL process to version 1.0 and i have some running instancs in that version
    now i have redeployed the same process to another version 1.1. is it possible to migrate the 1.0 instances to 1.1 in oracle SOA 11g?
    the problem is, when i redeploy the process to the same version, the process state is getting stale which should not happen
    can you pleasae tell to prevent the state going stale on redploy (or)
    migration of that instance to new instance version
    thanks in advance. expecting a solution at the earliest

    thanks,
    if so,
    i have an humantask activity in the process. in revision 1.0 , i have some instances which are running. it is exposed as a service which other services consume.
    now, if i redploy to the same revision, the state goes stale, so that we could not act on stale human tasks which should not happen
    what should i do in this case if i am unable to migrate to the revision?
    pleasse help..

  • String name = new String {...} what is this?

    Hi,
    Java beginner, moving from C++:
    protected String[] name = new String[] {
              Integer.toString(1),
    Integer.toString(2)
         };what does a bracket mean after new String[] ?
    Thanks,

    Thanks, I didn't know what to search for in
    google...
    Is it generalizable to any object?Why don't you try it with various objects and primitives? Then you'll find out for yourself.
    You can also read the JLS
    http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html
    or
    http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html
    Or any of a number of books or tutorials. This is basic stuff. It should be covered.
    Sun's basic Java tutorial
    Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    http://javaalmanac.com. A couple dozen code examples that supplement The Java Developers Almanac.
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's Thinking in Java (Available online.)
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java.

  • New String(byte[]) taking up huge space?

    Ok. I have a byte[] of approx. 5.000.000 bytes. Whenever, at any point, I try to create a String using this array by new String(array), my memoryusage increases by about 60/65 megabytes. Can anyone please explain me why on earth it's doing this?
    Note also that this space is not freed up by the GC (afterwards).
    Thanks in advance

    Actually, I've discovered some details about the swing textcomponents. They're very bad for 'simply' showing 2mb+ files.
    Check out these bugs; original and "more recent".
    It doesn't quite explain why putting a byte array to a string occupies twice the space, but it does seem to account for the huge memory increase when putting it to a JTextArea.
    String is immutable so it has to copy your char[] to
    a new char[] backing the String. If it used theSure thing, but I'm passing on a byte[] array, and afaik, it's not using this array and should only copy it. Once.
    Oh hey, could it be that the bytes are saved in unicode? That would double the size... and make sense...
    Oh and PS; Maybe you should read this if you really think strings are immutable... (although you are generally correct :))

  • "String str=new String("My String")" v.s. "String str="My String";

    -- what's the difference bet String str="My String"; to this
    String str=new String("My String");

    Its a subtle one. Its also been asked a hundred times before :-)
    When a java class is compiled it "interns" all the Strings it can find.
    Anywhere that you use that string, gets replaced with a reference to that string.
    So the first gets a reference to the interned String.
    The second creates a new String, using the interned String as an argument - results in reserving new memory.
    Take this code:
    String str1 = "My String";
    String str2 = "My String";
    String str3=  new String("My String");In effect the compiler turns it into something like this:
    String internedString = "My String"
    String str1 = internedString;
    String str2 = internedString;
    String str3 = new String(internedString);So initially, it only stores "MyString" once, and all your String variables point at that same memory space. As Strings are immutable in java (the contents never change) this is safe to do. str3 creates a NEW String, which reserves new memory, and copies the contents of internedString into it.
    So
    str1 == str2 (they point to the same bit of memory)
    str1 != str3 (str3 created a new String, so is in new memory)
    str1.equals(str3) (the contents of the strings are the same)
    Hope this helps,
    evnafets

  • HT3529 I have i0S7.0.2 on my iPhone 5.  I want to to send a new string of messages to someone but every time I type in the recipient's phone number, the old string of messages pop up.  Is there any way to start a new, fresh string?

    I have i0S7.0.2 on my iPhone 5.  I want to to send a new string of messages to someone but every time I type in the recipient's phone number, the old string of messages pop up.  Is there any way to start a new, fresh string?

    SadisticIron wrote:
    i just baught my first iphone and it is a jalbroken
    Buzz! Thank you for playing!
    Discussing jailbroken devices is forbidden here by the Terms of Service.
    You can not get help here.

  • Difference between str="Hai"; and str = new String("Hai");

    HI,
    String szFirst = "Hello World":
    String szSecond = new String("Hello World");What is the difference between the two types of string initialization?

    RajivGuna wrote:
    HI,
    String szFirst = "Hello World":
    String szSecond = new String("Hello World");What is the difference between the two types of string initialization?What do you think the difference is?

  • Why use of new String() in JboDomain constructor

    JDeveloper by default generates a constructor for String-based Jbo domains like this
      public MyDomain(String val)
        mData = new String(val);
        validate();
      }What reason is there for the use of "new String()"? I've changed all my domains
    to simply do mData = val. What would be wrong with that?
    -- Sebastian

    You change is ok. It's just a generic code generation routine that is not special-casing the String type.

  • Monitor object instantiation of an arbitrary class, e.g. new String(...)

    Hello,
    does anyone have an idee how to monitor object instantiation of arbitrary java class, e.g. new String(...).
    Is the 'VMObjectAlloc' the right place or should this be done using BCI?
    Many thanks,
    Christian

    Thanks a loot swamyv !!
    Can you give me any hint where such a step could be done? Should i "scan" the bytecode inside the CLASS_REPARE event processing? What would be the thing i'm looking for?
    Thanks in advance,
    Christian

Maybe you are looking for

  • How to restore library and iPod from external flash drive

    I had trouble getting my iPod to load new music after I got a new PC. I reinstalled iTunes and the new music loaded but the old music in my library and iPod were deleted. How do I transfer my music from my flash drive back to my library and iPod clas

  • HP LaserJet 2820 All-in-One fails to print on right side of the page

    I have HP LaserJet 2820 All-in-One for 1.5 years now and before the first set of cartridges run out of ink, the printed page comes out blur or no printing on the right side of the page. No smear on the right page.  It doesn't matter if I used color o

  • All offering not displaying in Learning Path

    Hi, We have created a course which contains 3 offerings (with different delivery modes), each offering have 1 class. When we attach this course to a learning path and an employee subscribes to this learning path, only one offering is getting displaye

  • Alternate BOMs and Purchase Requisitions

    Hi The scenario is that the material M1 has two alternate BOMs. These two alternate BOMs(A1 & A2) are specific to two different vendors(V1 & V2). During the planned order conversion to a Purchase Requisition, the business needs to decide/assign the v

  • Oracle RAC 11.2 on Windows without DNS and DOMAIN

    I am trying to install Oracle RAC 11.2 in windows 2008R2 64 bit which is on workgroup and no available DNS. I read that SCAN requires DNS and in case DNS is not available, then host file will do but only one SCAN address will do. Can anyone help me o