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)

Similar Messages

  • 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 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 ArrayList to a String[]

    Hi,
    How can I convert an ArrayList (only with strings) to a String[] ?
    I've tried this :
         public static String listToString(List l) {
              StringBuffer sb = new StringBuffer();
              Iterator iter = l.iterator();
              while (iter.hasNext()) {
                   sb.append(iter.next().toString());
                   if (iter.hasNext()) {
                        sb.append(',');
              return sb.toString();
    But what I get is an array of xxxxx@435634 (for example).
    Thanks a lot !

    Strings are Objects but not all Objects are Strings and at least one of the elements in your List is not a String.

  • How do I convert visa resource name into string?

    Could please anybody help? I have an ergent need. How do I convert visa resource name into string?
    Thank you in advance.

    Most times you do not need to convert it. Just wire it stright into what ever string input.
    See "Format Into Srting" or "Type Cast" functions
    Omar

  • How can i convert some caracteres of a String in bold characteres?? hELPME

    How can i convert some caracteres of a String in bold caracteres?? hELPME
    I have a JList and a DefaultListModel of Strings. So, i have many key words like "proccess", "if", "fi" that i want these characteres in bold.

    How i can use HTML in java to change a String to bold?
    example
    String str = "channel ";
    str = <b>str</b>;
    like this? syntax error =/

  • 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);

  • How can i convert JMS TextMessage into a String

    Please tell me,How can i convert A JMS TextMessage into a String

    http://java.sun.com/javaee/5/docs/api/javax/jms/TextMessage.html#getText()

  • How can I convert/read out from a string Hex (8-bit), the bit 0 length 1

    How can I convert/read out from Hex (8-bit), the bit 0 length 1 (string subset!!??) and convert it to decimal.
    With respect to one complement and two complement ?

    Just like Jeff, purely guessing here.
    It almost sounds like you just need to Read from Binary File?
    AND the 8-bit number with 1?
    Need more details.  What exactly do you have to start with?  What exactly are you trying to get out of it?  Examples help.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How can I convert a Waveform to a String-For​mat?

    Hello,
    I write with "SQL-Execute.vi" datas to an Access-file. The "SQL-Execute.vi" needs a statement in String Format. And that is my problem. My source-datas (that I want to save to Access) are Waveforms. How can I convert the Waveform datas to a String Format?
    Thanks for help!

    Wire the waveform to the Get waveform componants function...from that you get t0, delta t and the sample values. Now you can generate whatever string you want based on that information...
    You could e.g. wire the Y array to a for-loop in which you calculate the time of each sample by taking t0 and adding delta t multiplied with the array index, then you could convert the Y value and the time to strings using the seconds to time string and number to fractional string functions...etc etc...
    MTO

  • How do i convert an object into a string?

    has said above, im trying to convert a object to a string.
    here is what i ahve so far:
    Object nodeInfo = node.getUserObject()

    RTFM
    Object o =...
    String str = o.toString();

  • How do I convert a Variant of type=String to G data? (LV 5.1.1)

    I've tried to return a string in the Variant return of a VB function in a DLL. (I want to do this so that I can retain the interface and thus binary compatibility in the DLL.)
    When I use the DLL function in LabVIEW 5.1.1 I
    get an error in the call library function call (returning). It looks like there is a way to handle this in v 6.0 but I have to use 5.1.1 for this application. Is there a way for LV 5.1.1 to handle a Variant containing a string?
    Thanks
    Dave Karon
    Concepts NREC

    Hi Dave,
    you can use the type conversion function located under advanced -> data
    manipulation to convert the variant into a string.
    Henrik
    Dave Karon schrieb in im Newsbeitrag:
    [email protected]..
    > I've tried to return a string in the Variant return of a VB function
    > in a DLL. (I want to do this so that I can retain the interface and
    > thus binary compatibility in the DLL.)
    > When I use the DLL function in LabVIEW 5.1.1 I
    > get an error in the call library function call (returning). It looks
    > like there is a way to handle this in v 6.0 but I have to use 5.1.1
    > for this application. Is there a way for LV 5.1.1 to handle a Variant
    > containing a string?
    >
    > Thanks
    > Dave Karon
    > Concepts NREC

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

Maybe you are looking for