System.out on array of strings

I have a string array which is populated. when i attempt to output this array the following appears: [Ljava.lang.String;@1d64c37]. Why is it printing out the location of the object. How do I print out the actual content. I know i can do system.out(stringArray[posn]) to view each value, but is there a way of printing out the whole array???

public static String toString(String[] array)
    StringBuffer buf = new StringBuffer();
    if (array == null)
        buf.append("null");
    else
        buf.append("[");
        for (int i = 0; i < array.length; i++)
            if (i > 0) buf.append(", ");
            buf.append(array);
buf.append("]");
return buf.toString();

Similar Messages

  • Saving System.out text into array of Strings

    I've got a lot of strings, which are being inputed into System.out
    Is it possible to transfer symbols from System.out into array of strings?

    Do you mean in real time or after the fact parsing it?
    For a realtime solution you may want to look at creating a class that extends PrintStream, which rather than actually printing anywhere, creates this Array that you want. Then call System.setOut(PrintStream s) and give it your special PrintStream. Provide some methods to get at the Array data and you're off!

  • How to store Array of Strings in MS-Access

    Dear all,
    i am facing a problame from the couple of days can any one plzzzzzzz guide what should i do to over come my problame....>
    I want to store a String array in Microsoft Access database but i couldn't find the way how can i do so
    public class ArrayJDBC {
    /** Creates a new instance of ArrayJDBC */
    public ArrayJDBC() {
    public static void main(String[] args){
    System.out.println("main started");
    new ArrayJDBC().enterArray();
    System.out.println("main after data entry");
    public void enterArray(){
    Connection con = null;
    PreparedStatement pstm = null;
    String dataSource = "checkArray";
    String query = "INSERT INTO array(Object) VALUES(?)";
    String[] strArray = {"one","two","three"};
    con = new JDBCConnection().makeConnection(dataSource);
    try{
    pstm = con.prepareStatement(query);
    System.out.println("pstmt created");
    pstm.setObject(1,strArray);
    System.out.println("array seted as object");
    int r = pstm.executeUpdate();
    System.out.println("data updated "+r);
    pstm.close();
    con.close();
    }catch(SQLException se){
    System.out.println("Data could not be update "+se);
    this is my class the conncection is already established.
    i use updateObject() method but it doesnt work..
    plz guide me that how can i store
    strArray in Microsoft Access and also tell me that what should be the data type in my database i.e ms-access

    Well easiest way to do that is to create a single String where the values from array will be separated by some separator for example semicolon so you will get "one;two;three" this string you will store in database as a text, then when you read it back you need to parse it again to get an array of Strings. I am originally C# programmer there i would do serialization to XML and store it into database try looking here http://iharder.sourceforge.net/current/java/xmlizable/ they are creating XML Serializer.
    Peter.

  • How can i asign value to variables stored in an array of string?

    hi
    how can i asign value to variables stored in an array of string. i need to do it so that i can evaluate a math expression by usin those values. for example, i have a string array like [x, y, z, k]. now i need to asign 2.0 to x, 3.0 to y and so on. then if i type x+y, the program should evaluate the expression by usin x=2.0 and y=3.0. i am usin JEP for parsing and evaluating.
    any help or suggestion would be much apreciated.
    here is how i got the array
    System.out.println("Type first expression");
    BufferedReader br1 = new BufferedReader( new
                         InputStreamReader(System.in));
    String expression1 = br1.readLine();
    Jep jep = new Jep();
    Node node1 = jep.parse(expression1);
    TreeAnalyzer Ta1 = new TreeAnalyzer(node1);
    Map<Variable, Integer> map1 = Ta1.getVariables();
    /**The following will convert the variable names to a sorted array*/
         /**with the result in varNames.*/
    String[] res1 = new String[map1.size()];
                int i=0;
                for(Variable v:map1.keySet())
                    res1[i++]=v.getName();  
    System.out.println(Arrays.toString(res1));

    I could not use HashMap as those variables are to be retrieved from any expression typed by user and thus unknown to me beforehand.
    System.out.println("Type first expression");
    BufferedReader br1 = new BufferedReader( new
                         InputStreamReader(System.in));
    String expression1 = br1.readLine();
    Jep jep = new Jep();
    Node node1 = jep.parse(expression1);
    TreeAnalyzer Ta1 = new TreeAnalyzer(node1);
    Map<Variable, Integer> map1 = Ta1.getVariables();then i have converted them to a sorted array
    String[] res1 = new String[map1.size()];
                     int i=0;
                     for(Variable v:map1.keySet())
                         res1[i++]=v.getName();              
                     System.out.println(Arrays.toString(res1));now i need to assign random double values to those variables.
    and then use those double values for variables when evaluating the expression.
    pls help.

  • How to shrink an array of strings

    I am working on the method shift() which is similar to the one found in Perl. This method will take an array of strings and return the first string in the array. The resulting array should shrink by one element.
    However, I am having trouble with getting the array modified.
    I will show the output and the code.
    java DemoShift a b c
    Args len: 3 Argument #0: a
    bcc
    Args len: 3 Argument #1: b
    ccc
    Args len: 3 Argument #2: c
    ccc
    As you can see, I expect the array to get smaller each time, but I was unsuccessful. I have tried the following approaches:
    1. Convert the array of strings into StringBuffer by using append() and adding some delimeter, and then then using toString().split()
    2. Use ArrayList class to change the array length
    3. System.arraycopy.
    Here is the code. Let me know what do I need to get the array "args" get shrinked every time.
    <pre>
    import java.util.*;
    import java.io.*;
    class DemoShift
        public static void main(String args[])
            for (int counter = 0; counter < args.length ; counter++)
                System.out.println("Args len: " + args.length + " Argument #" + counter + ": " + shift(args));
                for (String st:args) System.out.print (st);
                System.out.println();
        public static String shift(String... args)
            StringBuilder sb = new StringBuilder(args.length-1);
            String firstString = args[0];
            String temp[] = new String[args.length -1];
            for (int counter = 1; counter < args.length; counter++)                                             
                sb.append(args[counter]);                                                                       
                sb.append("MYSPLIT");                                                                           
            temp = sb.toString().split("MYSPLIT");                                                              
            System.arraycopy(temp, 0, args, 0, temp.length);
            return firstString;
        }Edited by: vadimsf on Oct 25, 2007 10:17 PM

    I didn't really pay much attention to your problem, but will this help?
         public static void main(String[] args) {
              String[] test = {"test1", "test2", "test3"};
              for (String s : shift(test))
                   System.out.println(s);
         public static String[] shift(String[] arr)
              String[] a = new String[arr.length - 1];
              for (int i = 1; i < arr.length; i++)
                   a[i - 1] = arr;
              return a;

  • Creating an Array of Strings

    Does anyone know how to create an array of three strings? I need to then prompt a user for the three strings and enter them into the array...No idea how to code this at all.

    i'm not quite sure about your problem,anyway i've posted a snippet hope this helps,if not explain in detail.. :)
    import java.io.*;
    class ts{
         public static void main(String as[]) throws Exception{
              int j=3;//no of strings to be inputted i.e 3 in ur case
              String sArray[]=new String[j];
              for(int i=0;i<j;i++){
              BufferedReader reader = new BufferedReader
             (new InputStreamReader(System.in));
              System.out.println("Enter name"+(i+1));
              sArray[i] = reader.readLine();
              for(int i=0;i<j;i++){
                   System.out.println("array name"+(i+1)+" = "+sArray);

  • System.out will not flush before input

    Hello everyone,
    I am using Netbeans 5.5, JDK6, and J2EE. I am new to the environment so I wrote a test application that would prompt a user to enter a string and then echo it. I have:
    String str = "";
    BufferedReader br = new BufferedReader(new nputStreamReader(System.in));
    System.out.print("Enter a string: ");
    System.out.flush();
    try
    str = br.readLine();
    catch(IOException ex)
    System.out.print(ex.toString());
    System.out.print(str);
    What is really bizarre is that System.out will NOT flush no matter what. My application will always ask for input before it even prompts the user for the string. This is what the output looks like when running:
    init:
    deps-jar:
    compile:
    run:
    hello
    Enter an string: hello
    BUILD SUCCESSFUL (total time: 5 seconds)
    Notice how I had to enter the string first? The only way that I have seen that it flushes is if I used println() instead of print. But what if I don't want the prompt to have an end line in it. This just seems like weird behavior. Also, I have tried using a Scanner for input and the results are the same. Not really sure what to do. Any help would be most appreciated. Thanks.

    are you running this inside netbeans as well? the "console" view in netbeans (and eclipse, and probably other IDEs) is not a real console, it's a GUI component that the IDE writes to. it's behaviour isn't guaranteed to act like a real console. I've seen this sort of thing on eclipse before, but never used netbeans. but it still stands that an IDE's console view isn't an actual console/terminal window. that may well be the root of the problem

  • Redirect, System.out  ?

    Hi.
    I want to redirect System.out to a Swing Component like JTextArea, etc.
    try with printstream, Reader, etc. but i dont know how.!.
    I want to see, messages (The standard out) in a Swing Component.
    plis some help..
    tnks.

    I was using the Redirect method you made edna for my software and it works wonderfully when using strings, unfortunately I ran in to a strange problem which is fitting since my current objective is very strange.
    I am writing a piece of software that has an embedded jython interpreter in it. When I execute my jython scripts all the output went to the console and I had no direct way of saying append to this particular text area since I wasn't able to pass my Java GUI class in to the script.
    Thus redirecting my output with your method came in quite handy. This is where the problem comes in. I tried the println function in my regular java classes and all the primitive types worked fine, but within in the script only String worked. Here is the code for the println function
    PrintStream stdout = new PrintStream(System.out) {
       public void println(String x) {
          outputTextArea.append(x + "\n");
       public void println(int x) {
          outputTextArea.append(x + "\n");
       public void println(boolean x) {
          outputTextArea.append(x + "\n");
       public void println(Object x) {
          outputTextArea.append(x.toString() + '\n');
    };Here is the sample Jython code:
    import JythonScripter
    System.out.println(4) #fails to print correctly
    System.out.println("HelloWorld") #works
    System.out.println(10) #fails
    System.out.println("Goodbye Cruel World") #works
    If you have any advice on why strings would work but not other types I would greatly appreciate it.

  • To display 5 records out of 10 in String array

    HI ALL,
    Can anybody tell how to display first 5 records initially & rest 5 next time.
    this is wht i done
    String [] names = { "a", "b", "c", "d","e","f","g","h","i","j" };
    for(i=0;i<names.length;i++) // if i write for(i=o;i<5;i++) it display 5 records
    System.out.println(names); // here display all records
    i want initially to display first five records
    is there other way.
    actually i want this code in JSp when click on next button next 5 records will be displayed

    ok in you action performed method were you button is clicked
    you would need a global int as a pointer and local int say count
    //global int pointer initially set to 0
    int count  =0;
    while(count<5 && pointer<names.length())
        System.out.println(names[pointer]);
        count++;
        pointer++;
    }that should work.
    No to sure what Jsp is though.

  • I have jave 7 I'm trying underscore option in String.   as String strNum = "1000_000";System.out.println("..abc..."  Integer.parseInt(strNum)); but getting error. could you please help in this?

    Hi,
    There is a new feature added in java 7 on integer, called as underscore '_" and it is working fine
    if it is a normal int variable  but if it is coming with String jvm throw the error.
    if  any one of you have java8 installed on your PC can you check this is working on that version.
    int a = 1000_000;   
    String strNum = "1000_000";
    // System.out.println("..abc..."+ Integer.parseInt(strNum));
    System.out.println("a..."+a);
    Thank you,
    Shailesh.

    what is your actual question here?
    bye
    TPD

  • Temporarily routing System.out and System.err to a String

    Hi everybody,
    Does anyone know of a way to temporarily route System.out and System.err directly from the console into a String, then set it back to its default to the console? I know how to reroute to a text area:
    TextAreaOutputStream taos = new TextAreaOutputStream(yourTextArea);
    PrintStream ps = new PrintStream(taos);
    System.setErr(ps);
    System.setOut(ps);But it doesn't seem like there is either a way to reroute to a String or a way to switch back to the default routing afterward. Can anyone give me some advice on how to do this, please?
    Thanks,
    Jezzica85

    Too late to the party?
    import java.io.*;
    public class Redirection {
        public static void main(String[] args) {
            System.out.println("To console");
            PrintStream old = System.out;
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PrintStream ps = new PrintStream(baos);
            System.setOut(ps);
            System.out.println("To memory");
            System.out.print("No 'ln'");
            //System.out.flush(); //needed?
            System.setOut(old);
            System.out.println("To console again?");
            System.out.println("earlier I wrote...");
            byte[] data = baos.toByteArray();
            String message = new String(data);
            System.out.println(message);
    }

  • 2 parts: 1) integer array to string 2) string out to a jTextField

    I am completely new to Java and Netbeans, but I'm writing my 1st
    application that takes a "hex" character input from a jTextField,
    then converts it to an "binary" integer array. I then do a lot of bit
    manipulation, and generate a new "binary" integer array.
    String myhex = jTextField1.getText();
        int len = myhex.length();
        int[] binarray = new int[len*4];
            for (int i = 0; i < len; i++) {
               if (myhex.charAt(i) == '0'){
                  binarray[4*i]=0;
                  binarray[4*i+1]=0;
                  binarray[4*i+2]=0;
                  binarray[4*i+3]=0;
               else if (myhex.charAt(i) ==
               // repeat for '1 to 9' and 'a-f/A-F'
               // generate new integer array(s) using various bits from binarrayI realize it might not be the best way to do the
    conversion, but my input can be of arbitrary length,
    and it is my first time trying to write Java code.
    All of the above I've completed and it works...(thanks Netbeans
    for making the gui interface design a real breeze!)
    So I end up with:
    binarray[0]=0 or 1
    binarray[1]=0 or 1
    binarray[2]=0 or 1
    binarray[n]=0 or 1
    Where n can be any number from 0 to 63...
    I then manipulate the bits in binarray creating a new integer array
    and for the sake of expediency let's call it "newbinarray".
    newbinarray[0]=0 or 1
    newbinarray[1]=0 or 1
    newbinarray[2]=0 or 1
    newbinarray[n]=0 or 1
    Where n can be any number from 0 to 63...
    I first need to know how to convert this "newbinarray" integer array to a string.
    In the simplest terms if the first three elements of the array are [0][1][1],
    I want the string to be 011.
    Then I want to take this newly formed string and output it to a jTextField.
    string 011 output in JTextField as 011
    I've scoured the net, and I've seen a lot of complex answers involving
    formatting, but I'm looking for just a simple answer here so I can finish
    this application as quickly as possible.
    Thanks,
    Thorne Kontos

    Here's an example, not using NetBeans:
    import javax.swing.*;
    public class TextDemo extends JPanel
        public TextDemo()
            int[] newbinarray = {0, 1, 1};
            StringBuffer sb = new StringBuffer();
            for (int value : newbinarray)
                sb.append(value);
            String st = new String(sb);
            this.add(new JTextField(st));
        private static void createAndShowGUI()
            JFrame frame = new JFrame("TextDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(new TextDemo());
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args)
            javax.swing.SwingUtilities.invokeLater(new Runnable()
                public void run()
                    createAndShowGUI();
    }

  • Call a function, which name is in an Array of Strings...

    hey all
    i have a simple Temp class (made to check things) in a file called Temp.java with the following definition :
    public class Temp {
         int data1;
         int data2;
         public Temp (){
              data1=0;
              data2=0;
         (here i have get and set functions for both data1 and data 2, and i have the two following functions)
         public void printAdd(){
              System.out.println("Result : "+(data1+data2));
         public void printSubtract(){
              System.out.println("Result : "+(data1-data2));
    }i have another class called Server who has the following simple code :
    public class Server {
          public static void main( String args[] )
               String[] table={"printAdd","printSubtract"};
               Temp game=new Temp();
               game.setdata1(8);
               game.setdata2(4);
              //the following two calls work perfectly
               game.printAdd();
               game.printSubtract();
                   System.out.println(table[0]);
    //but the following does not...
               game.(table[0]);
    }as probably you have understood i am trying to call a function to the object game which name is in the String table... how can i actually made a call game.(THE_VALUE_OF_STRING_IN_AN_ARRAY) ...?

    i want to call the function printAdd() to the game object..
    but i want the program to find out the name of the function to call.. i want to execute the function whose name is at the array in position 0 -> table[0]
    so i want the program to resolve the table[0] to printAdd and the use it and call it on object game...

  • Strange behavior with System.out.println

    I was working with the following code:
    1. public class DemoChar {
    2. public static void main(String args[]) {
    3.
    4. char buf[] = new char[50];
    5. buf[0] = 'a';
    6. buf[1] = 'b';
    7. buf[2] = 'c';
    8. buf[3] = 'd';
    9. buf[4] = 'e';
    10. System.out.println( buf);
    11. }
    12. }
    if you print "buf", it really works; however if you change line 10 by :
    System.out.println("--->" + buf );
    The method "println()" doesn't write "--->abcde". The functionality doesn't the same. It will appear "----> [C@3e25a5"
    Could you help me?
    I don't understand that behavior. I am using "java version 1.6.0_07"

    buf's an array and thus is an object. object's don't inherently know how to represent themselves as Strings, so you have to do other things to make sure that they print out ok. To get a char array to print well, you could use the String method valueOf(...):
    public class DemoChar
      public static void main(String args[])
        char buf[] = {'a', 'b', 'c', 'd', 'e'};
        System.out.println(buf);  // this seems to call implicitly String.valueOf(buf)
        System.out.println("--->" + buf);  // this however seems to call buf.toString() with different results
        System.out.println("--->" + String.valueOf(buf));
    }Also, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, you can will need to paste already formatted code into the forum, highlight this code, and then press the "code" button at the top of the forum Message editor prior to posting the message. You may want to click on the Preview tab to make sure that your code is formatted correctly. Another way is to place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:
    &#91;code]
      // your code block goes here.
      // note the differences between the tag at the top vs the bottom.
    &#91;/code]or
    {&#99;ode}
      // your code block goes here.
      // note here that the tags are the same.
    {&#99;ode}Edited by: Encephalopathic on Aug 21, 2008 9:40 AM

  • Covert String Array to String

    Hey,
    I have this code that take a string
    EX:
    Straw? No, too stupid a fad, I put soot on warts
    and takes out the "?" and "," and places a space in their spot, then tokenizes the string so now all the spaces are gone (right?) then places the tokenized string into and array. Now I want that array into a string.
    Pretty much what I want to go from is
    this:
    Straw? No, too stupid a fad, I put soot on warts
    to:
    StrawNotoostupidafadIputsootonwarts
    here is my code
    import java.util.*;
    public class TrivialApplication {
         public static void main(String args[])
              System.out.println( "Hello World!\n" );
              String hello = "Straw? No, too stupid a fad, I put soot on warts";
              hello = hello.replace('?',' ');
              hello = hello.replace(',',' ');
              StringTokenizer tokenizer = new StringTokenizer(hello);
              String[] array = new String[hello.length()];
              System.out.println(tokenizer.countTokens());
              System.out.println(hello.length());
              int count = tokenizer.countTokens();
              int x = 0;
              while(tokenizer.hasMoreTokens())
                   array[x] = tokenizer.nextToken();
                   x++;
    }

    Sweet thanks man here is the finished code. I took out the array because it was now not needed.
    import java.util.*;
    public class TrivialApplication {
         public static void main(String args[])
              System.out.println( "Hello World!\n" );
              String hello = "Straw? No, too stupid a fad, I put soot on warts";
              System.out.println(hello + "\n");
              hello = hello.replace('?',' ');
              hello = hello.replace(',',' ');
              StringTokenizer tokenizer = new StringTokenizer(hello);
              StringBuffer buffer = new StringBuffer();
              int count = tokenizer.countTokens();
              while(tokenizer.hasMoreTokens())
                   buffer = buffer.append(tokenizer.nextToken());     
              hello = buffer.toString();
              System.out.println("New String with changes \n");
              System.out.println(hello);
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • DREADED 503 Service Temporarily Unavailable

    I have installed 9iAS 1.0.2.2.2a on a 9i Database, I have tried installing on remote machines, and on the same machine. I have done all the prerequisites, (JDBC/lib/, TNSnames.ora, Listener.ora, wdbsvr.app) etc. and no matter what I do I get the 503

  • Archiving Workflow with SARA; WORKITEM_WRI and WORKITEM_DEL

    I have been manually running the write and delete steps to archive completed workitems. I am now ready to set these jobs to run on a schedule through SM37. The write worked fine and created four archive files. However, the scheduled delete job only p

  • Unable to start weblogic server back end in linux

    Hi All,       i am  going to start weblogic 10.3.6 in production environment by using below commend but it gives error:        >cd /usr/app/oracle/Middleware/user_projects/domains/base_domain         >nohup startWebLogic.sh &        But when I use th

  • Adobe Exchange Panel will not install

    The Adobe Application Manager asks me to install the program, but then the download progress bar gets to about 5% then switches to"Retrying.."  and repeats the cycle.

  • Want to purchase music, but none come up on screen!

    I want to purchase music and so I go into the music store. However, when I click on say, "top 100 songs', none of the songs display on the page. I seem to only be able to buy albums, but I don't want the full album of some songs! What has happened??