Append String to Integer

Hi Guys,
I am trying to append a String to Integer like this;
String areacode = 020;
Integer phone_no = 21354214;
Integer full = areacode && phone_no;My problem is how to join the two datatypes to a single Integer value. Do anyone know how to go about this?
B

sabre150 wrote:
Skotty wrote:
Without debating the logic of doing such a thing...
Concatenate them as Strings, then convert that String back to an Integer.Your are on the top floor of the Eiffel Tower and a man is trying to climb over the safety netting but having trouble climbing the netting. You ask him why he is doing this and he says he has to get down to the ground as soon as possible but he has an irrational fear of lifts. Do you help him climb the safety netting or do you advise him that this is not a good idea and try to stop him?I get him to use my camera to take my picture.

Similar Messages

  • Convert string to integer

    package onjava;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import org.apache.soap.*;
    import org.apache.soap.rpc.*;
    import java.lang.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class CalcClient extends HttpServlet {
      public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"");
    out.println("\"http://www.w3.org/TR/html4/loose.dtd\">");
    out.println("<html>");
    out.println("<head>");
    out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
    out.println("<title>Substraction using SOAP</title>");
    out.println("</head>");
        URL url = new URL ("http://localhost/soap/servlet/rpcrouter");
    Integer p1=request.getParameter("param1");
    Integer p2=request.getParameter("param2");
    In the above statement i have to convert the string to integer because that has to be passed in my program as an argument to a function so please let me know how to do that
        // Build the call.
        Call call = new Call();
        call.setTargetObjectURI("urn:onjavaserver");
        call.setMethodName("subtract");
        call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
        Vector params = new Vector();
        params.addElement(new Parameter("p1", Integer.class, p1, null));
        params.addElement(new Parameter("p2", Integer.class, p2, null));
        call.setParams (params);
        // make the call: note that the action URI is empty because the
        // XML-SOAP rpc router does not need this. This may change in the
        // future.
        Response resp = call.invoke(url, "" );
        // Check the response.
        if ( resp.generatedFault() ) {
          Fault fault = resp.getFault ();
         out.println("The call failed: ");
         out.println("Fault Code   = " + fault.getFaultCode());
         out.println("Fault String = " + fault.getFaultString());
        else {
          Parameter result = resp.getReturnValue();
          out.println(result.getValue());
    out.println("</body>");
    out.println("</html>");

    Two possibilities: Try either java.lang.Integer.valueOf() or java.text.NumberFormat and its parse method.
    Either one will do what you want. I think Integer will be the simpler of the two.
    The code you have is obviously not correct, because getParameter returns a String:
    Integer p1=request.getParameter("param1");Do it like this:
    Integer p1=Integer.valueOf(request.getParameter("param1"));%

  • How to get the value of String in integer type

    how to get the value of String in integer

    {color:#0000ff}http://java.sun.com/javase/6/docs/api/java/lang/Integer.html#parseInt(java.lang.String)
    http://java.sun.com/javase/6/docs/api/java/lang/Integer.html#valueOf(java.lang.String){color}

  • Append string to stringbuffer in same line

    I have stringbuffer in which i append string thiesestring is of variable lengt
    has different value .I want that when i append string to stringbuffer it append
    to same line .I use append method of stringbuffer.But the whole value is not
    in same line it breaks into many line all lines are not of same size.
    Thanks

    Try making the textarea larger and see if it still
    shows on a new line...Textarea width is very large .There are many line break sometimes all lines
    are of different length so there is no issue of word wrap .I check the output
    sometimes it gives newline when it encounter space but not always .there are also spaces in single line .Sometimes it gives new line when it encounter >
    and sometimes it continue in same line after enconter > .
    Thanks

  • Logic behind string to integer typecasting..

    hi fourm,
    i'm siva. i learnt typecasting in java. but i'm still wondering how the string to integer typecasting works, what is the logic behind this casting. somebody please help me out...
    Advance thanking
    siva

        public static int parseInt(String s) throws NumberFormatException {
         return parseInt(s,10);
        public static int parseInt(String s, int radix)
              throws NumberFormatException
            if (s == null) {
                throw new NumberFormatException("null");
         if (radix < Character.MIN_RADIX) {
             throw new NumberFormatException("radix " + radix +
                                 " less than Character.MIN_RADIX");
         if (radix > Character.MAX_RADIX) {
             throw new NumberFormatException("radix " + radix +
                                 " greater than Character.MAX_RADIX");
         int result = 0;
         boolean negative = false;
         int i = 0, max = s.length();
         int limit;
         int multmin;
         int digit;
         if (max > 0) {
             if (s.charAt(0) == '-') {
              negative = true;
              limit = Integer.MIN_VALUE;
              i++;
             } else {
              limit = -Integer.MAX_VALUE;
             multmin = limit / radix;
             if (i < max) {
              digit = Character.digit(s.charAt(i++),radix);
              if (digit < 0) {
                  throw NumberFormatException.forInputString(s);
              } else {
                  result = -digit;
             while (i < max) {
              // Accumulating negatively avoids surprises near MAX_VALUE
              digit = Character.digit(s.charAt(i++),radix);
              if (digit < 0) {
                  throw NumberFormatException.forInputString(s);
              if (result < multmin) {
                  throw NumberFormatException.forInputString(s);
              result *= radix;
              if (result < limit + digit) {
                  throw NumberFormatException.forInputString(s);
              result -= digit;
         } else {
             throw NumberFormatException.forInputString(s);
         if (negative) {
             if (i > 1) {
              return result;
             } else {     /* Only got "-" */
              throw NumberFormatException.forInputString(s);
         } else {
             return -result;
        }Now where is the missing "logic".

  • Typecasting string to integer. need help

    Hi,
    I have the following statement which returns a String but i need to convert to an integer .
    properties.getProperty("MAXWIDTH");
    Can i do it this way,
    int width = (Integer) properties.getProperty("MAXWIDTH");
    But it gives me error stating that it cannot convert string to integer.
    Please help
    Purnima

    That's because the value returned from the
    getProperty() method is a String. You can convert it
    to an int, like this:int width =
    Integer.parseInt(properties.getProperty("MAXWIDTH"));[
    /code]oh so simple thanks
    Purnima

  • Append string in BPEL

    Hello,
    I have three values coming in the XML elements like
    FirstName, LastName and ZipCode
    I want to append these 3 using inside BPEL (using BPEL way) and then at the end also append current TimeStamp.
    So final appended string will look like FirstNameLastNameZipCodeTimeStamp
    How can i go about doing this appending ? also, Do I have to create a holder element that will hold this appended string ?
    thx
    d

    Hi,
    Use Concat(), inside Assign activity, give the values like, concat(FirstName,LastName,ZipCode, currectTime), offcourse this FirstName and other values will come from XML elements which you can select in the Expression Builder
    concat(bpws:getVariableData('inputVariable','payload','/ns4:FirstName'),bpws:getVariableData('inputVariable','payload','/ns4:LastName'),bpws:getVariableData('inputVariable','payload','/ns4:ZipCodeName'),xp20:current-time())
    Next you can create a new Variable and assign this value concat() to it.
    -Yatan

  • Convert text box string into integer

    i have an html file in which i m using a text box , for entering amount i m using that text box entry at next jsp. i want to convert amount string into integer for further processing. At next jsp i m using:-
    String amount= request.getParameter("bal");
    int ammount1= Integer.parseInt(ammount);
    and in sql query i m using amount1 as:-
    ResultSet rs1 = st.executeQuery("update saving set balance = balance - amount1 where saving.account_no = '" + acc +"'");
    my problem is i m getting following error:-
    server encountered an internal error and
    exception:- numberformat exception
    please help me as soon as possible

    int ammount1= Integer.parseInt(ammount).toString();
    good to put try block too..
    try
    int ammount1 = Integer.parseInt(ammount).toString();
    catch(NumberFormatException e)
    ...}

  • Converting String to integer?

    I looked on the sun forums and only found a lot of things that convert integers to Strings. Nothing to do the opposite.
    Does anyone know how I can convert a String to an int?

    coopkev2 wrote:
    an "A" from a "B"?? I don't understand what you are saying... I want to convert "100" to 100.
    Edit-- I'll be back soon.Read "A" as "Integer" and "B" as "String".
    In this case: read the [java.lang.Integer API|http://java.sun.com/javase/6/docs/api/java/lang/Integer.html] if there is a method which takes a String and returns an Integer or int.

  • Question about reading a string or integer at the command line.

    Now I know java doesn't have something like scanf/readln buillt into it, but I was wondering what's the easiest, and what's the most robust way to add this functionality? (This may require two separate answers, sorry).
    The reason I ask is because I've been learning java via self study for the SCJA, and last night was the first time I ever attempted to do this and it was just hellish. I was trying to make a simple guessing game at the command line, I didn't realize there wasn't a command read keyboard input.
    After fighting with the code for an hour trying to figure it out, I finally got it to read the line via a buffered reader and InputStreamReader(System.in), and ran a try block that threw an exception. Then I just used parseInt to get the integer value for the guess.
    Another question: To take command line input, do you have to throw an exception? And is there an easier way to make this work? It seems awfully complicated to take user input without a jframe and calling swing.
    Edited by: JGannon on Nov 1, 2007 2:09 PM

    1. Does scanner still work in JDK1.6?Try it and see. (Hint: the 1.6 documentation for the class says "Since: 1.5")
    If you get behaviour that doesn't fit with what you expect it to do, post your code and a description of our expectations.
    2. Are scanner and console essentially the same thing?No.
    Scanner is a class that provides methods to break up its input into pieces and return them as strings and primitive values. The input can be a variety of things: File InputStream, String etc (see the Scanner constructor documentation). The emphasis is on the scanning methods, not the input source.
    Console, on the other hand, is for working with ... the console. What the "console" is (and whether it is anything) depends on the JVM. It doesn't provide a lot of functionality (although the "masked" password input can't be obtained easily any other way). In terms of your task it will provide a reader associated with the console from which you can create a BufferedReader and proceed as you are at the moment. The emphasis with this class is the particular input source (and output destination), not the scanning.
    http://java.sun.com/javase/6/docs/api/java/util/Scanner.html
    http://java.sun.com/javase/6/docs/api/java/io/Console.html

  • How to compare a string with integer in jsp

    I have a field in database called as enddate
    i m trying to split the entire date and get date,month and year
    once i store the date in a variable called as fmdate which is string,
    i need to compare it with another integer.
    how can i compare it..heres my code
    stdate=RS.getString("start_date");
         fmdate=stdate.substring(8,10);
         fmmonth=stdate.substring(5,7);
         fmyear=stdate.substring(0,4);
    and this is where i want to compare the value of j to fmday...
    <td class="btext" valign="center">Day<select name="fmday">
    <%
    for(int j=1;j<=31;j++)
    String s;
    parseInt(s)=j;
    if (fmdate.equals(s))
    %>
    <option value="<%=j%>"><%=j%></option>
    <% } else { %>
    <option value="<%=j%>"><%=j%></option>
    <%
    } %>
    </select>
    pl help me...
    Thanks Srini

    j is an int, so you're just adding 0, not concatenating. Perhaps something like this would work.
    <%
      for(int j=1;j<=31;j++)
         String date = String.valueOf(j);
         if(j <= 9) {
            date = 0 + date;
         if (fmdate.equals(date)) {
    %>
      <option value="<%=date%>"><%=date%></option>
    <%
         } else {
    %>
      <option value="<%=date%>"><%=date%></option>
    <%
    %>Uhm, I assume there should be a 'selected' or something in one of the option tags?

  • Converting time string to integer (****) in Labview 5.1

    So i'm very new to labview, learning as i go, but as the title says, i
    need to convert a time string to an ineger so that it can be placed in
    an integer array which will be compiled then writen to file at a
    specified end ( by user ) I just want 4 digits **** to indicate
    military time. And unfortuanly i'm stuck with labview 5.1. Any help would be greatly appreciated.

    I believe the diagram I have attached may have been possible in LV 5.1.
    Try to wire this up and see if it works.
    The icons may have changed a little between LV 5.1 and 6.1.
    Ben
    Message Edited by Ben on 10-15-2005 02:49 PM
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction
    Attachments:
    Mitary Time.JPG ‏19 KB

  • Parsing a string to integer gives 0 in Integer

    Hi ,
    try
    usid = Integer.valueOf(usi).intValue();
    catch(NumberFormatException e)
         text = "NUMber";
    in the above code the value of usi is 4
    then parsing it is giving me 0 in usid
    try
    usid = Integer.parseInt(usi);
    catch(NumberFormatException e)
         text = "NUMber";
    I also tried the above code the result is same

    Also the OP didn't say which version of JDK he was using.
    With JavaSE5 and JavaSE6 , there's a new feature called autoboxing , which eliminates the need to cast from a String to an Integer , and then to get an int value .
    Insead one could simply write code like this and i works:
    Integer someInteger = 123;
    int anInt = 555;
    someInteger = anInt; 
    anInt = someInteger;Autoboxing and Autounboxing : http://java.sun.com/j2se/1.5.0/docs/guide/language/autoboxing.html
    But the article further adds:
    So when should you use autoboxing and unboxing? Use them only when there is an �impedance mismatch� between reference types and primitives, for example, when you have to put numerical values into a collection. It is not appropriate to use autoboxing and unboxing for scientific computing, or other performance-sensitive numerical code. An Integer is not a substitute for an int; autoboxing and unboxing blur the distinction between primitive types and reference types, but they do not eliminate it.
    Message was edited by:
    appy77

  • Change string to integer.

    I'm trying to change a string to an integer but my code isn't playing nice. I'm using (for example):
    Integer.parseInt(" 15")
    I've tried printing this to screen and it doesn't give me anything. Is there any way to get rid of the white space characters from a string? I can't use substring() as I have numbers up to 20,000 and I want to loop them using the same code.

    It should at least give you a java.lang.NumberFormatException
    This should work:
    Integer.parseInt(" 15".trim())

  • Converting a string to integer error

    I have this code
    temp = token.nextToken().toString();
    numero = Integer.parseInt(temp);
    Is is giving me a numberFormatExeption error Knowing that temp is a string
    can anyone help

    Add the following print statement and tell us exactly what it prints out. (You will probably know what the error is once you see what it prints.=
    temp = token.nextToken().toString();
    System.out.println("temp = \"" + temp + "\"");
    numero = Integer.parseInt(temp);

Maybe you are looking for

  • What I view the dbx files are of unknown format from TEMP directory?

    When you start Outlook Express DBX file to create a push, but after the program can not find it. There is a configuration change that? In the TEMP folder found files, but they are of unknown format, what I view the dbx files? 

  • Report Viewer in MS Access

    I've looked through the forums but haven't found a solution.  I've got a report viewer control (Crystal Reports 11) on an MS Access form.  I need to deploy the runtime files to client machines.  I've tried installing the merge modules but to no avail

  • Can't get Bridge to Open

    All of a sudden Bridge stopped opening and functioning within PS CS5.  Icon appears on my Mac but nothing else happens.  This is something relatively new.  Does anyone have any suggestions to correct?  I can't find anything in Preferences menu to hel

  • Bridge in CS3 starts then freezes.

    I have had trouble with Bridge ever since I installed CS3. On occasion I would have been using Bridge and randomly it would crash the whole computer necessitating a restart. As of a few days ago, it will start but then freeze. I click on a thumbnail,

  • Calender not syncing with WinXP

    My calendar is syncing fine between my Macbook and MobileMe, but not with my iPhone or WinXP?? Can I manually instruct the iPhone to sync? I have on WinXP.