Results 1 to 4 of 4
  1. #1
    innovo is offline Member
    Join Date
    Jul 2015
    Posts
    84
    Rep Power
    0

    Default Print to string?

    Hello again, I was just doing things in netbeans and I found that I can use
    Java Code:
     System.out.println(jComboBox1.getSelectedItem().toString());
    what it does basically is take a string value I already have in my UI and print it into the console. What is sad is I don't understand how to use
    Java Code:
     System.out.println(jComboBox1.getSelectedItem().toString());
    in order to assign the value to a string. I look at the ".toString()" and I'm thinking there HAS to be a way to tell java to assign that value to a string, as it's already doing it sort of -- I mean it seems to convert it to a string for sure .

    I have tried things like
    Java Code:
    String stuff;
    System.out.println(jComboBox1.getSelectedItem().toString(stuff));
    with no success. So I'm guessing there is something else I need to do in order to make this value assigned to a string.

    Is there a way to just use the value from
    Java Code:
    System.out.println(jComboBox1.getSelectedItem().toString());
    WITHOUT assigning it to another string? If I can only put the value into another string then how do I go about doing that?

    Java Code:
    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
            System.out.println(jComboBox1.getSelectedItem().toString()); // TODO add your handling code here:
        }
    ^ the code that I'm currently using (it's hardly anything, I know)

  2. #2
    Xen
    Xen is offline Member
    Join Date
    Jan 2015
    Posts
    86
    Rep Power
    0

    Default Re: Print to string?

    You're very verbose for such a simple question ;-).

    Are you absolutely certain you do not simply wish to do:

    Java Code:
    String s = jComboBox1.getSelectedItem().toString();
    ???.

    This is a simple assignment. toString() simply yields a String that you can assign to any String variable you want.

  3. #3
    innovo is offline Member
    Join Date
    Jul 2015
    Posts
    84
    Rep Power
    0

    Default Re: Print to string?

    oh...wow...I...I don't even..just...wow that was simple...but thanks!!!

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Print to string?

    tell java to assign that value to a string,
    You use an assignment statement to assign a value to a String:
    Java Code:
      String theTarget = value;  // assign a value to a String
    WITHOUT assigning it to another string?
    Can you explain what the problem is with assigning it to a String?
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. How to print string value from UI?
    By innovo in forum New To Java
    Replies: 2
    Last Post: 07-27-2015, 03:03 PM
  2. Pls help to print string in given format
    By know.how in forum New To Java
    Replies: 2
    Last Post: 08-31-2011, 01:43 PM
  3. using for-loop to print out a string
    By baumboards in forum New To Java
    Replies: 27
    Last Post: 03-17-2011, 04:47 PM
  4. Print String from an Array
    By adityasirohi in forum New To Java
    Replies: 2
    Last Post: 02-18-2010, 04:10 PM
  5. I can only print string literals
    By leeavital in forum New To Java
    Replies: 1
    Last Post: 12-11-2009, 01:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •