Doubt in Strings

I have a string suppose 80000.00000
i want to strip off the zeros after the decimal point..and show only 80000 ..how do i do it?/.,Please help

rajaram: substring() not subString() and str not "str"
@OP Do you know in advance that everything after the dot will be zero? If not, you will have to check for that. Depending on what you are trying to do (rather than how you are trying to do it) you may be able to avoid having the zeros in the first place by properly formatting an int value.

Similar Messages

  • Doubt in String Equals

    Doubt in String Equals_
    if(filePath != "") {
         getExcelData(filePath);
    }same as
    if(!filePath.equals("")) {
         getExcelData(filePath);
    }The can both be used interchangeably right ?

    kajbj wrote:
    (You should really open a textbook and read about Strings, or google)fortunatly i know this :)
    if you do
    String str = "abc"
    str =="abc" // will always return true.
    but str==(new String("abc")) // will always return false.
    But as per the query posted i am referring to the first case :)

  • Doubt about string.intern()

    Hello
    I have a doubt about string.intern() method.
    The document says
    When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the String.equals(Object) method, then the string from the pool is returned.
    So what is the point of using this intern() method with == or != operators if it aleady calling to equals method internally?
    eg:
    if (studentObject.getName().intern() == "Student Name") {}cannot be better than
    if (studentObject.getName().equals("Student Name")) {}Can someone please explain?

    Easy dude.
    >
    Why do you need to optimize it?>
    Because i want to.
    I would avoid the whole stupid 100 line if-else by doing a Map of type->object and then just clone() the object. But maybe that might not be suitable or "fast enough" for you.I cannot do above because object have it's own behaviors varying at run time
    eg - class One has setOne method and class hundred has setHundred method
    . Even if i use a map and clone it again i have to use above comparison for setting those behaviours.
    Explain your actual problem you're trying to solve, with actual cases. What are these "one" and "Hundred" classes really? Or is your project so top secret that you can't tell us?It is not secret but big. And I need to make the question understandable. If I post the whole code no one will looking at it.
    Now you asking so please have a look.
    still I have cleaned up many.
    My initial question was how to bit speed up the comparison? And can't i use intern() Because here if I got plenty of rectangles(it is the last) performace sucks.
    for (CObject aObject : objList) {
                if (aObject.getType().equals(SConstant.TEMPLATE)) { /* process Template */
                    Template tObj = (Template) aObject;
                    org.apache.velocity.Template template = VelocityTemplateManager.getInstance().getObjectTemplateFromFile(retemplateProperties.getProperty("PAGE"));
                    VelocityContext context = new VelocityContext();
                    StringWriter writer = new StringWriter();
                    context.put(retemplateProperties.getProperty("BAND_OBJECT"), dtmBand);
                    tObj.setTags(writer.toString());
                } else if (aObject.getType().equals(SConstant.LINE)
                        && !isInBandandBandAutoAdjust(aObject)) {
                    Line object = (Line) aObject;
                    org.apache.velocity.Template template = VelocityTemplateManager.getInstance().getObjectTemplateFromFile(retemplateProperties.getProperty("LINE"));
                    VelocityContext context = new VelocityContext();
                    StringWriter writer = new StringWriter();
                    updateContextWithCheckShifting(context, object);
                    context.put(retemplateProperties.getProperty("LINE_OBJECT"), object);
                    template.merge(context, writer);
                    object.setTags(writer.toString());
                } else if (aObject.getType().equals(SConstant.IMAGE) /* process Image */
                        && !isInBandandBandAutoAdjust(aObject)) {
                    REImage imageObject = (REImage) aObject;
                    org.apache.velocity.Template template = VelocityTemplateManager.getInstance().getObjectTemplateFromFile(retemplateProperties.getProperty("IMAGE"));
                    VelocityContext context = new VelocityContext();
                    updateContextWithCheckShifting(context, imageObject);
                    context.put(retemplateProperties.getProperty("IMAGE_OBJECT"), imageObject);
                    mageObject.setTags(writer.toString());
                   else if (aObject.getType().equals(SConstant.RECTANGLE) /* process Rectangle */
                        && !isInBandandBandAutoAdjust(aObject)) {
                    Rectangle rectangleObject = (Rectangle) aObject;
                    org.apache.velocity.Template template = VelocityTemplateManager.getInstance().getObjectTemplateFromFile(retemplateProperties.getProperty("RECTANGLE"));
                    VelocityContext context = new VelocityContext();
                    StringWriter writer = new StringWriter();
                    updateContextWithCheckShifting(context, rectangleObject);
                    context.put(retemplateProperties.getProperty("RECTANGLE_OBJECT"), rectangleObject);
                    template.merge(context, writer);
                    rectangleObject.setTags(writer.toString());
                }And masijade
    Thank you very much for the better explanation.

  • Doubt in String handling...

    Hi
    Here i have a code snippet.
    public class StringComp
         public static void main(String[] args)
              String a = "abc";
              String b = "def";
              String c = "abcdef";
              String d = "xyz";
              String e = "xyz";
              a+=b;
              System.out.println("Value of a = :" + a);
              System.out.println("Value of c = :" + c);
              System.out.println("Value of d = :" + d);
              System.out.println("Value of e = :" + e);
              if(a==c)
                   System.out.println("TRUE");
              else
                   System.out.println("FALSE");
              if(e==d)
                   System.out.println("TRUE");
              else
                   System.out.println("FALSE");
    if i compile and run this code snippet i am getting the result as
    Value of a = :abcdef
    Value of c = :abcdef
    Value of d = :xyz
    Value of e = :xyz
    FALSE
    TRUE
    here i add the value of a and b to a. so a=abcdef, value of c also abcdef.
    but if i check (a==c) the result is False why??
    Can anyone tell me how the string is handled in java (behind the scene) where they are stored ? and how the == operator works on String?
    thanks in advance
    chithrakumar

    Strings are pooled. This means that if you writeString a = "1";
    String b = "1";you have a good chance that a == b.
    For new Strings (as "abc" + "def" returns), the pool is bypassed. This explains why "abc + "def" != "abcdef". To make sure a String is pooled, use intern (). ("abc" + "def").intern () == "abcdef", guaranteed.
    This is all very opaque behaviour and you shouldn't really rely on this in your code, except in very rare circumstances (extreme performance concerns or if you're stuck with an identity hash map [not that that's very likely]).

  • Doubt in String Parsing

    Hi,
    "23:BE|2009:A@Banglore"
    i need to parse the above string and retrieve the data's.
    Now i am using the StringTokenizer and my code is this,
    String sz = "23:BE|2009+A@Banglore";
              StringTokenizer szTkn = new StringTokenizer(sz, ":");
              System.out.println(" : " + szTkn.nextToken());
              szTkn = new StringTokenizer(szTkn.nextToken(), "|");
              System.out.println(" | " + szTkn.nextToken());
              szTkn = new StringTokenizer(szTkn.nextToken(), "+");
              System.out.println(" + " + szTkn.nextToken());
              szTkn = new StringTokenizer(szTkn.nextToken(), "@");
              System.out.println(" @ " + szTkn.nextToken());
              System.out.println(" " + szTkn.nextToken());is there any good way to do this?

    vijay wrote:
    You can use backreferencing to capture any group in a matching patterns.
    Take a look at this:
    http://download.oracle.com/javase/tutorial/essential/regex/groups.html
    I don't see how 'backreferencing' comes into this since the OP only needs the content of field values between separators without any direct reference to what has been found before.
    Since the original code suggests the fields are always there and always in the same order I think it is easier still just to use split()
    String sz = "23:BE|2009+A@Banglore";
    String[] splitSz = sz.split("[:|+@]");

  • Doubt in String

    Hi Members,
    Is there any method to check whether a string contains any special characters or not.
    Venkat

    just use the link posted above, and keep a look out for "Since: 1.5"
    Or:
    http://java.sun.com/j2se/1.4.2/docs/api/
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html

  • Doubt in String class

    What is the exact difference between
    String s=new String("xxxxxxx");
    String s="xxxxxxx"; ?
    Please let me know
    rgds
    Mohan S

    Read the Java Language Specs people.
    If I do this:
    String a = "A";
    String b = "A";How many "A"'s are in memory?
    The answer: 1.
    Doing this:
    String a = new String("A");First thing that happens is that "A" will be put in memory. Then a reference to "A" will be created (new String()), then your creating a reference (String a) and assigning your new String to it.
    The new String() creates a new object referencing the same string in memory.
    Hope this clarifies.
    It's explained better in JLS
    3.10.5 String Literals
    4.3.3 The Class String
    And the VM Spec
    2.3 Literals
    String literals and, more generally, strings that are the values of constant expressions are "interned" so as to share unique instances, using the method String.intern.

  • Basic Doubt regarding string comparision

    I have the following code:
    RegisterForm rf = (RegisterForm)form;
    String user = rf.getUsername();
    DTO ourdto = DBconnection.getDTO();               
    String pass = ourdto.getPword();When I print user,*pass* both the strings print "*pojo*"
    Now the condition I have to satisfy is
    pseudo code ---- if(*user* isequal to pass) { proceed forward }.
    I have used .equals but it is returning false,used equalsIgnoreCase and isContentEquals both are returning false.
    Could someone tell me if there is any method that can compare "pojo" to "pojo" and return a true.
    .

    sidster wrote:
    I have used .equals but it is returning false,used equalsIgnoreCase and isContentEquals both are returning false.Then they're not equal.
    Could someone tell me if there is any method that can compare "pojo" to "pojo" and return a true.
    String str = getUserInputOrWhatever();
    if ("pojo".equals(str)) {
      // the string was "pojo"
    }

  • Doubt about string comparison

    Hi,
    This may sound the simplest and the most stupid question to most of u reading it. But still share your knowledge.
    Let say we have four Strings defined as
    String s = "something";
    String s1 = "something";
    String t = new String("something");
    String t1 = new String("something");
    now if I compare this strings using '==' operator, This is what happens.
    System.out.println(s==s1); // answer is true
    System.out.println(t==t1); // answer is false
    Why the 1st SOP returns true if java does not treat strings as primitive and creates objects for every string eventhough it is instantiated with literals?

    The answer is:
    Java does a String pooling...
    why it give true, for the first case is
    s == s1
    because all this refers to the value in the String pool.. t and t1 are separate Objects although they have the same value("something"). So... when you do t == t1 you check if t and t1 are refering to the same Object(reference comparison), and since they are referencing 2 distinct Objects, the comparison gives false.
    Cheers !

  • Please simplify - doubt in String and StringBuffer

    in output of StringTest1 StringBuffer take more time than String concatenation using + operator.
    and in output of StringTest2 String concatenation using + operator take more time than StringBuffer
    please simplify..
    public class StringTest1 {
    public static void main(String[] args){
               //Test the String Concatination
              long startTime = System.currentTimeMillis();
              for(int i=0;i<5000;i++){
              String result = "This is"+ "testing the"+ "difference"+ "between"+
                                    "String"+ "and"+ "StringBuffer";
              long endTime = System.currentTimeMillis();
              System.out.println("Time taken for string concatenation using + operator : "
                                              + (endTime - startTime)+ " milli seconds");
               //Test the StringBuffer Concatination
               long startTime1 = System.currentTimeMillis();
               for(int i=0;i<5000;i++){
              StringBuffer result = new StringBuffer();
                                 result.append("This is");
                                result.append("testing the");
                                result.append("difference");
                                result.append("between");
                               result.append("String");
                               result.append("and");
                               result.append("StringBuffer");
              long endTime1 = System.currentTimeMillis();
              System.out.println("Time taken for String concatenation using StringBuffer : "
                                                 + (endTime1 - startTime1)+ " milli seconds");
    }output:
    Time taken for String concatenation using + operator : 0 milli seconds
    Time taken for String concatenation using StringBuffer : 15 milli seconds
    public class StringTest2 {
    public static void main(String[] args){
              //Test the String Concatenation using + operator
              long startTime = System.currentTimeMillis();
              String result = "hello";
              for(int i=0;i<1500;i++){
              result += "hello";
              long endTime = System.currentTimeMillis();
              System.out.println("Time taken for string concatenation using + operator : "
                                              + (endTime - startTime)+ " milli seconds");
              //Test the String Concatenation using StringBuffer
              long startTime1 = System.currentTimeMillis();
              StringBuffer result1 = new StringBuffer("hello");
              for(int i=0;i<1500;i++){
              result1.append("hello");
              long endTime1 = System.currentTimeMillis();
              System.out.println("Time taken for string concatenation using StringBuffer :  "
                                              + (endTime1 - startTime1)+ " milli seconds");
    }output:
    Time taken for string concatenation using + operator : 63 milli seconds
    Time taken for String concatenation using StringBuffer : 0 milli seconds

    As jverd said - in the first class, your String concat is only done once. Add/replace this code to your original and see what you get"
    {code} String results = "This is"+ "testing the"+ "difference"+ "between"+
    "String"+ "and"+ "StringBuffer";
    Object o = results;
    for(int i=0;i<500000;i++){
    results = "This is"+ "testing the"+ "difference"+ "between"+
    "String"+ "and"+ "StringBuffer";
    if (i < 10 ) System.out.println("same result: "+(o == results));
    }{code}
    Now made just one change ( appending +i to that String each time ) as follows:
    {code} String results = "This is"+ "testing the"+ "difference"+ "between"+
    "String"+ "and"+ "StringBuffer";
    Object o = results;
    for(int i=0;i<500000;i++){
    results = "This is"+ "testing the"+ "difference"+ "between"+
    "String"+ "and"+ "StringBuffer"+i;
    if (i < 10 ) System.out.println("same result: "+(o == results));
    {code}
    Then, also in the first class, create your StringBuffer BEFORE the loop and "delete(0,result.length());" within the loop. This speeds it up and makes for a better comparison.
    Next, increase your loop size to something that will produce more consistent results (I used half a million).
    Lastly (or approximately so, at least) change the first part of your first class - using String - to the following:
    {code} results = "This is";
    results += "testing the";
    results += "difference";
    results += "between";
    results += "String";
    results += "and";
    results += "StringBuffer";
    results += i;
    {code}
    Now you have a more legitimate comparison and you will see a real difference.

  • Doubt with String class

    Please tell me why String class objects are immutable. Why it was designed like that?

    Read Java tutorials.Thanks for your reply. But tutorial says thatString
    objects are immutable but they dont say why
    they
    made
    as immutable.Welcome swathi.reply #4 is the best answer Ithink.
    But please look at my reply #8Please look at reply#2 in the other thread.But reply #2 was mine. I dont understand what you say? Please help me.

  • Doubt on Strings.

    Hi,
    I have the following code.
    while(<cond>)
    String str = "A1:" + <some value returned for above code>;
    Above code was resulting in memory issues. Replacing the statement,
    String str = "A1:" + <some value returned for above code>;
    with
    String str = new String( "A1:" + <some value returned for above code>);
    solved the memory issues.
    But I don't understand how the problem is solved.
    Can anyone throw some light on this.
    Thanks, Anil.

    But I don't understand how the problem is solved.
    Can anyone throw some light on this.The only difference between the two cases is that in the second case you always get a unique reference to each String even when they're equal. In the first case all equal Strings will be given the same reference.

  • Doubt about  a null value assigned to a String variable

    Hi,
    I have a doubt about a behavior when assigning a null value to a string variable and then seeing the output, the code is the next one:
    public static void main(String[] args) {
            String total = null;
            System.out.println(total);
            total = total+"one";
            System.out.println(total);
    }the doubt comes when i see the output, the output i get is this:
    null
    nulloneA variable with null value means it does not contains a reference to an object in memory, so the question is why the null is printed when i concatenate the total variable which has a null value with the string "one".
    Is the null value converted to string ??
    Please clarify
    Regards and thanks!
    Carlos

    null is a keyword to inform compiler that the reference contain nothingNo. 'null' is not a keyword, it is a literal. Beyond that the compiler doesn't care. It has a runtime value as well.
    total contains null value means it does not have memory,No, it means it refers to nothing, as opposed to referring to an object.
    for representation purpose it contain "null"No. println(String) has special behaviour if the argument is null. This is documented and has already been described above. Your handwaving about 'for representation purpose' is meaningless. The compiler and the JVM don't know the purpose of the code.
    e.g. this keyword shows a hash value instead of memory addressNo it doesn't: it depends entirely on the actual class of the object referred to by 'this', and specifically what its toString() method does.
    similarly "total" maps null as a literal.Completely meaningless. "total" doesn't 'map' anything, it is just a literal. The behaviour you describe is a property of the string concatenation operator, not of string literals.
    I hope you can understand this.Nobody could understand it. It is compete nonsense. The correct answer has already been given. Please read the thread before you contribute.

  • ORA-02050 transaction string rolled back, some remote DBs may be in-doubt

    Hi...guys...How ru all...
    I got follwoing error...and I searched in google but there is not clear information..plz help me ...
    Error Message: ORA-02050 transaction string rolled back, some remote DBs may be in-doubt
    Error Cause:
    Network or remote failure during a two-phase commit.
    Action:
    Notify operations; remote databases will automatically re-sync when the failure is repaired.
    SQL>SELECT local_tran_id, global_tran_id, state, mixed, host, commit#
    FROM dba_2pc_pending
    LOCAL_TRAN_ID GLOBAL_TRAN_ID STATE MIX HOST COMMIT#
    5.44.98254 JICRACDB.e1ab4089.5.44.98254 collecti no JICN\ROOM9 1132915640
    ng 7-ITC
    SQL> SELECT local_tran_id, in_out, database, dbuser_owner, interface
    2 FROM dba_2pc_neighbors
    3 /
    LOCAL_TRAN_ID IN_OUT DATABASE DBUSER_OWNER INT
    5.44.98254 in JIC N
    5.44.98254 out RC_DBLINK JIC N
    SQL> ;
    1 select state, tran_comment, advice from dba_2pc_pending
    2* where local_tran_id ='5.44.98254'
    SQL> /
    STATE TRAN_COMMENT ADVICE
    collecting
    so how can I delete distributed transaction..plz provide me any Metalink Docids.

    See if following MOS note helps.
    Manually Resolving In-Doubt Transactions: Different Scenarios (Doc ID 126069.1)

  • ORA-01591: lock held by in-doubt distributed transaction string  error

    Hi Gurus,
    I am getting the error
    ORA-01591: lock held by in-doubt distributed transaction string error while running once procedure.
    Procedure basically inserts 2 tables and update 1 table.
    The order of execution is given below.
    However I get the error as table _a locked.
    Can you please help me how to handle this ?
    Begin
    Insert into table_a values (values1, value2); -- (our DB)
    Insert into table_b@remote_DB values (value1, value2); --( REMOTE DB)
    update table C ; -- (our DB)
    commit; -- when I debugged I get exception with the sql error above in this commit.
    End;

    Tina wrote:
    Hi Gurus,
    I am getting the error
    ORA-01591: lock held by in-doubt distributed transaction string error while running once procedure.
    Procedure basically inserts 2 tables and update 1 table.
    The order of execution is given below.
    However I get the error as table _a locked.
    Can you please help me how to handle this ?
    Begin
    Insert into table_a values (values1, value2); -- (our DB)
    Insert into table_b@remote_DB values (value1, value2); --( REMOTE DB)
    update table C ; -- (our DB)
    commit; -- when I debugged I get exception with the sql error above in this commit.
    End;
    01591, 00000, "lock held by in-doubt distributed transaction %s"
    // *Cause:  Trying to access resource that is locked by a dead two-phase commit
    //          transaction that is in prepared state.
    // *Action: DBA should query the pending_trans$ and related tables, and attempt
    //          to repair network connection(s) to coordinator and commit point.
    //          If timely repair is not possible, DBA should contact DBA at commit
    //          point if known or end user for correct outcome, or use heuristic
    //          default if given to issue a heuristic commit or abort command to
    //          finalize the local portion of the distributed transaction.

Maybe you are looking for

  • Ask again:  Where can I find source code for CPRM algorithm?

    Hi, everyone. Where can I find reference implementation or some sample codes for CPRM(content protection for recordable media) algorithm? Can anyone help? Information about CPRM can be find here, http://www.4centity.com/ JAVA version is preferred and

  • How do I merge 2 pdf files into one file?

    How do I merge 2 pdf files into one file?

  • Scroll text in ALV column using OO ALV grid

    Hi All, I have displayed ALV grid on the screen which has four columns. One of the columns is a text field with text255 domain. This Column is also editable. I have following problem and need help; The column for some reason displays only 130 chars.

  • Time machine to airdisk taking forever...maybe a gig an hour

    So I set up my Airport Extreme Airdisk as a Time Machine disk. I started the first backup and its taking forever...if I am lucky its sending a gig an hour on an 802.11n machine. Any thoughts?

  • How to change export report option

    hi Im using Crystal report plug in for Eclipse. I want to export report to PDF, EXCEl etc... for that there is Export report option. I want to customize that export report dialog box. How can I do that? I want to set default path to export file. defa