How to convert an int to a String

Hi, just wanting to know is anyone could help me with convertin a primitive int into a String, currently I have
String mod = Integer.valueOf(n);
but with this i keep getting an error which says, - cannot resolve symbol - method valueOf(int)
Can anyone please help me. thanks.

it should be
String mod = Integer.toString(n);

Similar Messages

  • How to convert an int variable into String type

    hi everybody
    i want to know how to convert an interger variable into string variable
    i have to implement a code which goes like this
    Chioce ch;
    for(int i=0;i<32;i++)
    // here i need a code to convert the int variable i into a string variable
    ch.add(String variable);
    how do i convert that int variable i into a String type variable??
    can anyone help me?

    Different methods:
    int a;
    string s=a+"";or
    String.valueOf(int) is the better option because Int.toString() generated an intermediate object to get the endresult
    Ema

  • How to convert an int array to string array?

    Hi,
    Can anyone please help me with this question?
    int number={4,6,45,3,2,77};
    I like to convert this into a list and sort
    List mylist = Arrays.asList(number);
    Collections.sort(mylist);
    But first I need to convert the int array to String array.
    Please advise. Thanks.

    If you want to convert your int array to a String array, you have no choice but doing a conversion element by element in a for loop.
    However, if the sort method doesn't behave as desired, you can use the one with 2 parameters, the second parameter being a comparator class.
    Check the javadoc for more information : http://java.sun.com/j2se/1.3/docs/api/java/util/Collections.html
    /Stephane

  • Converting an int to a string

    i want to know how to convert an int to a string .
    I have tried toString() but it says can't dereference an int.
    any ideas ????
    thanks

    What I mean by the object being null is, say for example, you have the following method:
       public String combine(Object o1, Object o2){
          return o1.toString() + o2.toString();
       }This method will throw a NullPointerException if either or both o1 and/or o2 are null. If you use it like so:
       public String combine(Object o1, Object o2){
          return String.valueOf(o1) + String.valueOf(o2);
       }This will always work. (I know someone out there would say that this would return a String like "nullnull" if both are null, and so forth and so on, but hey, you get my drift.) I'm also not saying the you can't not check if either o1 or o2 is null before proceeding, so the following also works:
       public String combine(Object o1, Object o2){
          String s = null;    // I'm using this instead of StringBuffer for
                              // simplicity's sake so don't get this wrong
          if (o1 != null){
              s = o1.toString();
          if (o2 != null){
              s += o2.toString();
          return s;
       }As you can see, there's no right or wrong way in programming as long as you achieve the result. The only thing that would matter is how clean your code is, how efficient your code is, and how maintainable your code is.

  • How can I convert an int to a string?

    Hi
    How can I convert an int to a string?
    /ad87geao

    Here is some the code:
    public class GUI
        extends Applet {
      public GUI() { 
        lastValue = 5;
        String temp = Integer.toString(lastValue);
        System.out.println(temp);
        showText(temp);
      private void showText(final String text) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            tArea2.setText(text + "\n");
    }

  • How do I convert an int to a String?

    How do I convert an int to a String?

    You can also use any of these methods if you need to get more complicated:
    Integer.toString(int i)
    Integer.toBinaryString(int i)
    Integer.toHexString(int i)
    Integer.toOctalString(int i)
    Integer.toString(int i, int radix)

  • How to convert an int variable into Number

    Hi all,
    I am using Jdeveloper 11.1.1.2
    When I insert a row in a entity object I want to create another row in another entity object, but when I am setting the attribute for the new row I have a problem.
    Here is the code:
    int a = EO1Impl.paramA;
    NameEO2Impl.setAttribute("Attribute1", a);
    The error is that variable a is an int, while Attribute1 is a Number.
    How can convert an int to a Number.
    Thank you.

    Andrea9,
    If a, as you say is an int, and assuming you mean an oracle.jbo.domain.Number,
    NameEO2Impl.setAttribute("Attribute1", new oracle.jbo.domain.Number(a));works just fine.
    John

  • How to convert ResultSet's value to String

    Dear JDC's
    plz tell me how to convert ResultSet's value to String.
    kashif

    I want to read a whole array from a table into a String[]
    and then send it to another servlet before I forward it all to anther servlet with request.setParameter.....
    Any ideas how to solve it....that is how far I got so far:
    rs=pgresult("select count (answer) from answers where qid="+idnum);
                                                           numberofquestions = rs.getInt("mynumber");     
                                                           rs=pgresult("SELECT answer FROM answers WHERE qgroup="+qgroup);
                                                           allanswers = new String[numberofquestions];
                                                           allanswers = (String[])rs.getArray(1).getArray();     
                                                           req.setParameter("allanswers",allanswers);
                                                           RequestDispatcher dispatcher = req.getRequestDispatcher("editanswers");
                                                           dispatcher.forward(req,res);
    Tobi

  • How to convert from int to string

    Can anyone help me on how to convert int to string?
    Thanks,
    Q

    int i = 3
    String S = i + ""
    i will be promoted to String automatically when the above expression is evaluated

  • How to convert a "text variable" to String with plugin

    Hello,
    I am currently developing a InDesign (CS5) plugin, where I need to manipulate text variable.
    From the plugin I want to convert the "text variable" to string (in principle I should use the method "VariableToString (..)" of "ITextVariable")"
    My problem is, how to find the text varial from its name (I think I should use the method "FindLocationsUsed(..)" of "ITextVariableSuite") and then convert it to String
    I don't know how to use interfaces ITextVariable and ITextVariableSuite
    Plugin implemented in C++ language
    thank you

         InputStreamReader in=new InputStreamReader(fis);
          StringWriter out=new StringWriter();
          char[] buffer=new char[8192];
          int sizeRead;
          while ( ( sizeRead=in.read(buffer, 0, 8192) ) != -1 )
            out.write(buffer, 0, sizeRead);
         String content=out.toString();

  • How to convert an int number to a byte array, and how to convert back?

    Hello, everybody,
    Just as the topic, if I have an int number(which should have 32-bit, or 4-byte), how can I convert it into a byte array. And also, how to convert it back.
    Thank you in advance!

    Alternatively you can use ByteBuffers to do this work for you
    // to a Byte Array
    int originalInt =...;
    ByteBuffer myBuffer = ByteBuffer.allocate(4);
    myBuffer.putInt( originalInt );
    byte myArray[] = myBuffer.array();
    // and back to an int
    ByteBuffer myOtherBuffer = ByteBuffer.wrap(myArray);
    int finalInt = myOtherBuffer.getInt();

  • How to convert an int to String ???

    please hlp me

    This question has been asked so many times we're all just sick of it. Why don't you search the forum for the simple answer?

  • Convert an int to a String

    Hi,
    when i try to do the following its an error
    int totalmarks;
    String Totalmarks;
    Totalmarks = totalmarks.toString();
    could any one tell me how to do it correctly
    Thank you

    A lot of alternatives, but you can't do new String(int..).
    1. Integer.toString(totalmarks)
    2. String.valueOf(totalmarks) will call Integer.toString(totalmarks)
    3. ""+totalmarks will use the StringBuffer and append "" and totalmarks which again will call String.valueOf(totalmarks) which again will call Integer.toString(totalmarks)

  • Converting type INT to type String...possible?

    Hi
    I basically have a stored string that I want to add numbers to, like adding a phone numbers digits to eachother or a calculators numbers to eachother in seperate instances. Is this possible?
    So say I ask the user to input a number (single), can this then be added to the string field and then perhaps looped (dont tell me how to do that - I will try that myself) to create a string of 10 or more numbers?
    Thanks for any help

    Thanks but I have to start with a param of INT before
    adding it to the string, and I cant seem to do this
    with casting (String) FIELDNAME - I get the
    Inconvertible types error[url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html#toString(int)]Integer.toString()

  • How to substract an int from a String?

    Hi,
    Here is my problem,
    I have to substract 4 integers out of a single string (in a single input using the JOptionPane.showInputDialog)
    these 4 integers are seberated by spaces (any number of spaces)
    I have to sign each number to an int variable
    also I have to multiply these 4 integers with doubles to get a final double variable result
    I need urgent help please
    (hint: it's about string manuplation)
    Thanks

    Hi,
    Here is my problem,
    I have to substract 4 integers out of a single string
    (in a single input using the
    JOptionPane.showInputDialog)
    these 4 integers are seberated by spaces (any number
    r of spaces)
    I have to sign each number to an int variable
    also I have to multiply these 4 integers with doubles
    to get a final double variable result I have no idea what you're asking. Can you clarify? Maybe provide some sample input and what the output will be.
    I need urgent help please I promise you, nobody here cares about your urgency, and mentioning it is guaranteed NOT to get you help any faster. If it has any effect at all, it will be the opposite--some people might decide to delay or skip answering your question simply out of irritation at you mentioning your urgency.
    (hint: it's about string manuplation)Yeah. We got that, thanks.

Maybe you are looking for

  • Updated to Yosemite and now my iPhone won't show up in iTunes. Visible in iPhoto though

    So i've updated my iMac to Yosemite and everything is running the latest operating system. When I plug my iPhone 6 in it is visible in iPhoto but won't show up in iTunes, Any ideas? Much appreciated

  • Error got  in Communication channel monitoring ( component monitoring)

    Hi Experts, When i executed the RFC from R3, i got the below error in runtime work bench. please help me out if any one knows, i already gone through some of sdn line, but i am not able to get exact solution. com.sap.aii.af.rfc.RfcAdapterException: e

  • External Authentication with LDAP

    Has anyone integrated external authentication of Essbase with LDAP? I've searched discussion groups, websites with no luck, and of course, Essbase documentation doesn't help either. Any additional documentation will help.Thanks in advance!

  • Differences between object and object references

    What's the differences between object and object references? To me, it seems the same, but I am sure there are differences. Student s = new Student("Joe",20); s is an object of class Student. Can we say s is an object reference of class Student? Plea

  • Aspect ratio list

    I thought I posted this question a while ago, but can't find it... If 854x480 is a 16:9 ratio, what's the next one down, and the next one after that, etc? I'm trying to get a good file size for exporting to the web so I need to experiment with a few