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!

Similar Messages

  • How to get formatted text into arrays

    Dear experts and helpers,
    For my project I import an RTF file and then read the data from it into 3 arrays. This works fine when just using the string contents of the paragraphs. However, the final script should be able to read and replace formatted text...
    Why use the intermediate arrays? Because otherwise I need to switch back and forth between two fm-documents (and one may be a book component).
    The imported file starts with a number of lines separated into two items by a TAB (» denotes a TAB, in FM \x08)
    [[Garneau, 1990 #12]]    »   [9]
    The right item may also be locally formatted text, e.g. [9]
    Then follow the same (or smaller) number of paragraphs with formatted text like this:
    [9] » D. Garneau, Ed., National Language Support Reference Manual (National language Information Design Guide. Toronto, CDN: IBM National Language Technical Centre, 1990.
    Is it possible to replace in the body of the function below the following piece
      while(pgf.ObjectValid()) {
        pgfText = GetText (pgf, newDoc);
        gaBibliography.push(pgfText);
        pgf = pgf.NextPgfInFlow;
    with this
      while(pgf.ObjectValid()) {
        gaBibliography.push(pgf);
        pgf = pgf.NextPgfInFlow;
    Do I need a special declaration of the array gaBibliography ?
    And how to get the right part of the intro lines as formatted thingy into array gaFmtCitsFmt ?
    Currently I read into arrays only the 'strings' (function GetText not shown):
    var gaFmtCitsRaw  = [];                           // left column in processed RTF
    var gaFmtCitsFmt  = [];                           // right column in processed RTF
    var gaBibliography= [];                           // bibliography lines from processed RTF
    // filename is something like E:\_DDDprojects\FM+EN-escript\FM-testfiles\BibFM-collected-IEEE.rtf
    function ReadFileRTF (fileName) {
      var nCits=0, nBib = 0, openParams, openReturnParams, newDoc, pgf, pgfText ;
      var TAB = String.fromCharCode(8);               // FM has wrong ASCI for TAB
      var parts = [];
      openParams = GetOpenDefaultParams();
      openReturnParams =  new PropVals(); 
      newDoc = Open (fileName, openParams, openReturnParams); 
      pgf = newDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;  // get first pgf in flow
    // --- read the temp/formatted citations 
      while(pgf.ObjectValid()) {
        pgfText = GetText (pgf, newDoc);
        if (pgfText.substring (0,2) == "[[") {        // citation lines start with [[
          parts = pgfText.split(TAB);                 // get the two parts of the line
          gaFmtCitsRaw.push (parts[0]);               // Push the result onto the global array
          gaFmtCitsFmt.push (parts[1]);
          pgf = pgf.NextPgfInFlow;
        } else { break }
    // --- read the bibliography
      while(pgf.ObjectValid()) {                      // until end of doc
        pgfText = GetText (pgf, newDoc);
        gaBibliography.push(pgfText);
        pgf = pgf.NextPgfInFlow;
      newDoc.Close (Constants.FF_CLOSE_MODIFIED);
    } // --- end ReadFileRTF
    The next questions then will be how to modify Ian Proudfoot's FindAndReplace script to handle formatted text as replacement. IMHO i will need to use copy/paste ...

    Klaus,
    Working with text is about the most complicated thing to do within FrameMaker. It seems counter-intuitive, since it is about the easiest thing to do with the GUI. But alas, once you remove the ability to select with a mouse and type with a keyboard, text becomes a wild jungle of complexity.
    Text ranges are not too bad, once you get the general idea. It is just that... a range of text, like something you would select with a mouse. Like a mouse selection, it starts before some character in some paragraph and ends after some character in some paragraph. It may be the same paragraph, which is a selection within a paragraph. The character can even be the same, which is then just an insertion point (cursor) somewhere.
    So, a text range is a data structure that defines two paragraphs and two characters. In the jargon of scripting, the character is called an "offset." An offset is simply the number of characters past the beginning of said paragraph, where 0 is the beginning.
    For example, if you want to capture the first five characters of a paragraph as a text range, you can do this, where 'pgf' is some paragraph object:
    var textRange = new TextRange();
    textRange.beg.obj = pgf;
    textRange.beg.offset = 0;
    textRange.end.obj = pgf;
    textRange.end.offset = 5;
    If you want to capture a whole paragraph, change that last line to the number of characters in the pgf, or you can do this:
    textRange.end.offset = Constants.FV_OBJ_END_OFFSET;
    ...where that constant is just some built-in thing that means "get me to the end of whatever." It's a convenience of the interface.
    I'll also note that a text range is actually just an array of two text location structures, one named 'beg' and one named 'end.' If you think of a text location as defined by paragraph and an offset from the first character, maybe that will make more sense.
    Text item structures are a whole new mess of complexity. I can't possibly go into an explanation of them here.
    I think that many ES developers (definitely myself included) still use the FDK documentation because it is considerably more comprehensive. The two interfaces are largely parallel, but of course somewhat different in the language syntax. Consider that as a potential resource.
    Russ

  • How can I show a System.out.println(""); into a JSP?

    Is a simple doubt that would help me a lot to reach other thing that I wished reach with a JSP.
    Thank you!!!

    Hi!!!
    Thank you to answer me......my question�is because�my problem is a little more complicated��let me tell you�.
    My problem is that I wish to do some queries to a table of a Municipalities DB, I have read about that....and according with the exemples....my JSP...should be running and executing very well....but I haven�t had success with that...:(
    My JSP file is:
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <!-- Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.-->
    <head>
    <title>Query of Municipalities</title>
    </head>
    <body bgcolor=#FFFFFF>
    <font face="Helvetica">
    <h1>
    <font color=#DB1260>
    Municipalities List
    </font>
    </h1>
    <%@ page import="
    weblogic.db.jdbc.*,
    weblogic.html.*,
    java.sql.*
    " %>
    <p>
    <%
    Connection conn = null;
    try {
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:DESAPool");
    catch (Exception e) {
    e.printStackTrace();
    Statement stmt = conn.createStatement();
    stmt.execute("select * from cat_municipio");
    ResultSet rs = stmt.getResultSet();
    while (rs.next()) {
    System.out.println(rs.getInt("cve_municipio") + " - " + rs.getInt("cve_sepomex") + " - " + rs.getString("desc_municipio"));
    stmt.close();
    conn.close();
    %>
    <p>Please call Mary with any updates ASAP!
    <p>
    <font size=-1>Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    </font>
    </font>
    </body>
    </html>
    My result obtained is the following:
    Municipalities List
    Please call Mary with any updates ASAP!
    Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    I don�t obtain nothing.....is like DB table were without information......but in reality the DB table has information.....and I can obtain it with the following JSP:
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <!-- Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.-->
    <head>
    <title>Query of Municipalities</title>
    </head>
    <body bgcolor=#FFFFFF>
    <font face="Helvetica">
    <h1>
    <font color=#DB1260>
    Municipalities List
    </font>
    </h1>
    <%@ page import="
    weblogic.db.jdbc.*,
    weblogic.html.*,
    java.sql.*
    " %>
    <p>
    <%
    Connection conn = null;
    try {
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:DESAPool");
    // Fetch all records from the database in a TableDataSet
    DataSet dSet = new TableDataSet(conn, "cat_municipio").fetchRecords();
    TableElement tE = new TableElement(dSet);
    tE.setBorder(1);
    out.print(tE);
    } catch (SQLException sqle) {
    out.print("Sorry, the database is not available.");
    out.print("Exception: " + sqle);
    } catch (Exception e) {
    out.print("Exception occured: " + e);
    } finally {
    if(conn != null)
    try {
    conn.close();
    } catch(SQLException sqle) {}
    %>
    <p>Please call Mary with any updates ASAP!
    <p>
    <font size=-1>Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    </font>
    </font>
    </body>
    </html>
    and with this JSP I obtain all the following information:
    Municipalities List
    CVE_MUNICIPIO CVE_SEPOMEX DESC_MUNICIPIO
    1 1 ACAJETE
    2 2 ACATENO
    3 3 ACATLAN
    4 4 ACATZINGO
    5 5 ACTEOPAN
    Now...I need that the first JSP work very well, because...with that way...I can do queries and obtain the needed results for showing them in the Browser......
    So, I already find out�.that�any string that I send to the browser with System.out.println(); isn�t showed�.so it is the reason of my question�..how I can see my results of a query using a loop (like a for, while) resolving it....I think my problem would be resolved.
    So...I hope you understand me, and you could help me please...thanks.....
    Mary
    P.D. I also attempted with the following JSP...but the result is the same....I don�t obtain none result...
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <!-- Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.-->
    <head>
    <title>Query of Municipalities</title>
    </head>
    <body bgcolor=#FFFFFF>
    <font face="Helvetica">
    <h1>
    <font color=#DB1260>
    Municipalities List
    </font>
    </h1>
    <%@ page import="
    weblogic.db.jdbc.*,
    weblogic.html.*,
    java.sql.*
    " %>
    <p>
    <%
    Connection conn = null;
    try {
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:DESAPool");
    catch (Exception e) {
    e.printStackTrace();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select CVE_MUNICIPIO, CVE_SEPOMEX, DESC_MUNICIPIO from cat_municipio");
    while (rs.next()) {
    System.out.println(rs.getInt(1) + " - " + rs.getInt(2) + " - " + rs.getString(3));
    rs.close();
    stmt.close();
    conn.close();
    %>
    <p>Please call Mary with any updates ASAP!
    <p>
    <font size=-1>Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    </font>
    </font>
    </body>
    </html>

  • How can i put a system.out.println into txt file

    i want to generate a txt file instead of system.out.println. for the output How can i do that and what code can i use for that??
    Edited by: crystalarun on Oct 14, 2007 11:40 AM

    suppose u ant output in "Output.txt"
    then code can be
    PrintStream out = new PrintStream(new FileOutputStream("Output.txt"));
    System.setOut(out)

  • Add an array of strings into ArrayList

    Hi Guys
    I would like to add an array of strings into an ArrayList, which i have implemented by using the following code:-
    String[] strReturnWords = getInput2(line);
    List.add(strReturnWords);strReturnWords returns an array of Strings.
    How do i retrieve the array of strings from the ArrayList. I have tried
    String[i] strString = List.toString();Am i doing this correctly, are their any other ways??
    Many thanks
    Jason

    That should work.NO. That wont work AT ALL.
    This:
    String[] arrayOfString = new String[listName.size()];Is not right. The number of elements in the list is MUCH different
    then the size of the array which is an element in the list.
    This:
    arrayOfStrings[ i] = (String)listName.get(i);Will fail. The list contains an Object of StringArray not an Object of String.
    import java.util.*;
    public class StringList{
    public static void main(String[] args){
         String text = "this is some text";
         String[] words = text.split("\\s+");
         ArrayList list = new ArrayList();
         list.add(words);
         String[] array = (String[])list.get(0);
         for(int i = 0; i < array.length; i++){
         System.out.println("Word: " + array);

  • Logger ConsoleHandler strangeness on System.out

    Hi all,
    I have been scratching my head all day trying to work out what is going wrong with the following code. It's the minimal test case I could come up with to replicate something we're seeing in our codebase. I'd be greatly obliged if somebody could please offer some insight.
    In this code I am using the java.util.logging API to create 2 loggers. In the first Logger I am adding a custom handler which inherits from ConsoleHandler but redirects the messages to System.out instead of System.err. It's very simple, but I suspect there is a subtlety here which is the cause of the problem.
    Both Loggers should inherit the parent logger by default... which should also spit out logs to System.err
    However, if you run the code you will only see one piece of text output in your console and not 4 as expected. Basically, none of the System.err messages get printed! I've tested this on Java 5 in both Apple Leopard and 64bit Ubuntu.
    import java.util.logging.ConsoleHandler;
    import java.util.logging.Logger;
    public class TestLogger {
         static class StdOutConsoleHandler extends ConsoleHandler {
              public StdOutConsoleHandler() {
              super();
              setOutputStream(System.out);
         public static void main(String[] args) {
         Logger logger1 = Logger.getLogger("test1");
         logger1.addHandler(new StdOutConsoleHandler());
         logger1.info("You should see this twice... but I bet you only see it once.");
         Logger logger2 = Logger.getLogger("test2");
         logger2.addHandler(new ConsoleHandler());
         logger2.info("You won't even see this one at all!");
         // BUG: Where has the stderr logging gone?
    }Incidentally, if you rearrange the code so that logger2 is created first... it works a little bit more like you'd expect, but not entirely. How strange!
    Logger logger2 = Logger.getLogger("test2");
    logger2.addHandler(new ConsoleHandler());
    logger2.info("You will now see this twice in System.err, as expected");
    Logger logger1 = Logger.getLogger("test1");
    logger1.addHandler(new StdOutConsoleHandler());
    logger1.info("You should see this twice... but I bet you only see it once.");

    Thanks for the Java 6 report. I thought perhaps it was fixed in Java 6 because I only seen this when I backported. Perhaps I just didn't notice it before now.
    My preferred solution is still to copy the entire ConsoleHandler code into a new class and change the reference from System.err to System.out. The point of my class is to have logging on stdout through this handler, I don't want to see anything on stderr*
    *actually I do want to see output on stderr, but only if the Level is high enough. By using a stdout handler, it can be set to capture at Level.CONFIG and then I have a ConsoleHandler (i.e. stderr) listening to Level.WARNING and above. But that's besides the point. I also have FileHandlers and all sorts for use in tomcat. It's best to have each Handler only output to one location.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Redirecting System.out to a JTextArea

    How can I redirect the System.out Stream into a JTextArea?
    I found the method System.setOut(PrintStream out) but I don't know
    how to get the PrintStream of my TextArea.

    I don't know if this is the most efficient way but it provides an example of using Pipes:
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class TextAreaStream extends JTextArea implements Runnable{
         private static final PipedOutputStream _pipeOut = new PipedOutputStream();
         static{
                   System.setOut( new PrintStream(_pipeOut) );
         private InputStream _pipeIn;
    private byte[] buffer = new byte[256];
         public TextAreaStream(){
              this(1,10);
         public TextAreaStream(int numRows, int numCols){
              super(numRows, numCols);
              Thread t = new Thread(this);
              t.setDaemon(true);
              t.start();
              try{
              pipeIn =  new BufferedInputStream(new PipedInputStream(pipeOut));
              catch(IOException e){
                   System.err.println("Error creating pipe: "+e);
         public void run(){
              while(true){
                   try{
                        //blocks at read
                        int bytesRead = _pipeIn.read(buffer);
                        append(new String(buffer,0,bytesRead));
                   catch(IOException e){
                        System.err.println(e);
         public static void main(String[] args){
              JFrame f = new JFrame();
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JTextArea text = new TextAreaStream();
              text.setBorder(BorderFactory.createTitledBorder("System.out"));
              f.getContentPane().add(text);
              //Add an input component
              JPanel north = new JPanel(new FlowLayout(FlowLayout.LEFT));
              final JTextField field = new JTextField(25);
              north.add(field);
              north.add(new JLabel("Add text, press Enter"));
              f.getContentPane().add(north, BorderLayout.NORTH);
              field.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent e){
                        System.out.println(field.getText());
                        field.setText("");
    f.setSize(600, 400);
              f.show();
    }

  • System.out to out Redirect

    I've got class Interpreter from BeanShell. This class runs dynamically cnostructed java code.
    The problem:
    Interpreter.eval("some commands");prints results into System.out,
    while I want it to print results to "out" implicit variable of a JSP implementation.
    How can I solve this problem?

    If only I could make System.out to print into array of strings - it would solve my problem...

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

  • Array of String ?

    Hi everybody,
    Could anybody help me this( I finished step 1 and step 2, but not step 3 )
    Step1: I type a whole string when i were asked by computer:
    "I am a new student of Java programming"
    Step 2: I want to break this sentence into words as: "I", "am", "a", "new", "student"...
    Step 3: And then, I want to store these words into an array of string. But I do not know how?
    Here is my codes:
    // Step1
    String wholeString = keyboard.readLine();
    // Step2:
    StringTokenizer myString = new StringTokenizer(wholeString, " ");
    String[] mySubStrings = new String[myString.countTokens()];
    for(int i =0; myString.hasMoreTokens(); i++)
    mySubStrings[i] = new String(myString.nextToken());
    for(int j = 0; j< mySubStrings.length; j++)
    System.out.println(" " + mySubStrings[j]);
    // Step 3 (Could any body help me. I tried it many times, but i got errors !)
    Thank you very much in advance. I appreciate.
    still_learn

    Thank you very much, danperkins. Actually i missed typing.
    But could you or anybody help me do step 3 ? OK I made it more briefly and simply like this:
    I have 5 strings: "I", "am", "a","new", "student".
    How can i store them into array of string as "
    String[] myStorage = {"I", "am", "a", "new", "student"};
    How could i do that?
    Thank you very much.
    still_learn

  • Replacing words in an array of strings

    hi
    im trying to create a method that takes three arrays of strings as parameters and replaces some words in one of them
    heres my code
    class A0
    public static void main (String[] args)
    int index;
    String[] in = {"life","is","a","bowl","of","pits"};
    String[] what={"pits", "bowl"};
    String[] with={"chocolates", "box"};
    String[] result=new String [in.length];
    result=findAndReplace(in, what, with);
    for (index=0;index<in.length;index++)
    System.out.print(result[index]+" ");
    static String[] findAndReplace (String[] in, String[] what, String[] with)
    int index1;
    int index2;
    String[] newString= new String [in.length];
    for (index1=0;index1<in.length;index1++)
    for (index2=0;index2<what.length;index2++)
    if (in[index1]==what[index2])
    newString[index1]=with[index2];
    else
    newString[index1]=in[index1];
    return newString;
    ok so it's supposed to print life is a box of chocolates, only it prints life is a box of pits???pls help

    i figured it out

  • Problem with national characters calling System.out.print(...)

    I need to develop an application printing spanish characters like "�" (ce trencada) "�", "�", etc.
    The problem is when I type
    System.out.print("�")in my application, I get "plus-minus" symbol while executing it.
    Anyone can help me, please?
    Thank you in advance.

    check the list of fonts available. You can use the following code for the purpose.
      public static void main(String args[])
            String fonts[] = getFontNames();
            for(int i = 0; i < fonts.length; i++)
                System.out.println(fonts);
    public static String[] getFontNames()
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    return ge.getAvailableFontFamilyNames();

  • Can't resolve java.lang.System.out

    Hi,develpoers:
    Does anyone know how to fix this problem:
    C:\cai\VCTest\robo-sdk\build\sun\robot\vision\Search1.java:57: cannot resolve symbol
    symbol : variable out
    location: class java.lang.System
    System.out.println("Look returned null VisionImage");
    I don't know why this error occured because this application ran well last day.
    Thanks in advance!
    Cai

    But there is no other variable named "System". All the fields of "System" cannot be used but System.exit(1)can work. And all the methods of String like trim()can not work. Below is the codes:
    package sun.robot.vision;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import SK.gnome.twain.*;
    import sun.robot.vision.*;
    import java.lang.System;
    import java.io.*;
    public class Search1
    public Search1() {
    public void searchPuck(String colourString) {
    Image i;
    boolean found = false;
    VisionImage image = null;
    byte colour = VisionImage.NO_COLOUR;
    if (colourString.equals("red"))
    colour = VisionImage.RED;
    if (colourString.equals("blue"))
    colour = VisionImage.BLUE;
    if (colour == VisionImage.NO_COLOUR) {
    System.out.println("Invalid colour. Must be one of red or blue");
    System.exit(1);
    while (!found) {
    TwainSource source = null;
    /* grab an image from the camera */
    try {
              try{      source=TwainManager.getDefaultSource();}catch(Exception e){}
                   i=Toolkit.getDefaultToolkit().createImage(source);
              image = new VisionImage(i);          
              if (image == null) {
    System.out.println("Look returned null VisionImage");//here got the error
    System.exit(1);
    } catch (VisionException ve) {
    // System.out.println("Unable to look");
    // System.out.println(ve.getMessage());
    System.exit(1);
    image.setDebugLevel(2);
    if (image.canYouSee(colour) == false){}
    //do nothing
    else
    found = true;
    VisionObject puck = image.getVisionObject(colour);
    if (puck == null) {
    // System.out.println("Internal Error: ball is null object");
    System.exit(1);
    /* Print a message to tell the user that we've found the ball and
    * where it is relative to the robot
    StringBuffer saw = new StringBuffer("I see the ball " );
              StringBuffer size = new StringBuffer( );
    if (puck != null) {
    int pos = puck.getPosition();
    switch (pos) {
    case VisionObject.LEFT:
    saw.append("to the left of the robot");
    break;
    case VisionObject.CENTRE:
    saw.append("in front of the robot");
    break;
    case VisionObject.RIGHT:
    saw.append("to the right of the robot");
    break;
              size.append(image.getHeight()+","+image.getWidth());
    // System.out.println(size.toString());
    // System.out.println(saw.toString());
    Point c = puck.getCentre();
    mc.send(3);
    //System.exit(0);
    public static void main(String[] args) {
    if (args.length < 1) {
    //System.out.println("Usage: Fetch <ball_colour>");
    System.exit(1);
    //System.out.println("it is me");
    // String colourString = args[0].toLowerCase();
         String colourString = args[0];
         colourString= colourString.trim();//trim cannot work
    Search1 f = new Search1();
    f.searchPuck(colourString);
    Any help will be highly approciated.
    Cai

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

  • Reading a text file and transferring values into array

    Hi,
    I have a problem. So what I am trying to do is that, I read a text file and insert specific values from the text file into an array for future needs.
    But I have to make sure that there is no duplicate entries. So thats what I have but, my method takes forever to finish...
    here is my code:
    String nomFichier = "Test_" + numTest + "_" + date + ".txt";
            String ligne = "";
            int z = 0;
            int j = 0;
            BufferedReader lecteurFichier = new BufferedReader(new FileReader(nomFichier));
            while ((ligne = lecteurFichier.readLine()) != null) {
                if (z > 3)
                    String valeur = "";
                    String dist = "";
                    boolean unique = true;
                    String [] chiffre = ligne.split(";");
                     if (intervalleAnalyser == 1)
                        valeur = chiffre[3];
                        dist = chiffre[4];
                    if (intervalleAnalyser == 2)
                        valeur = chiffre[2];
                        dist = chiffre[4];
                    if (intervalleAnalyser == 3)
                        valeur = chiffre[1];
                        dist = chiffre[4];
                    if (z == 4) {
                        intervalleDiagramme[j] = valeur;
                        j++;
                    if (z > 4) {
                        for (int i = 0; i < intervalleDiagramme.length; i++)
                             for (int x = 0; x < i; x++)
                                 if(intervalleDiagramme[i] == intervalleDiagramme[x])
                                    unique = false;
                        if (unique)
                            intervalleDiagramme[j] = valeur;
                        j++;
                z++;
            lecteurFichier.close(); // toujours fermer le fichier

    Hi,
    Thanks for your reply,
    1) Yeah I have a method that asks the question and assigns it to a variable.
    2) Well the z will stop once there is no lines to read no?
    for the set.add(), I am not that familar...
    I changed bit a code and I have this now:
    if (z > 4) {
                        for (int i = 0; i < intervalleDiagramme.length; i++)
                            System.out.println(intervalleDiagramme);
    if(intervalleDiagramme[i].equals(valeur))
    System.out.println(intervalleDiagramme[i] + " " + valeur);
    unique = false;
    if (unique)
    intervalleDiagramme[j] = valeur;
    EDIT:
    I figured a way to assign " " to all the values in my array. But I get this error:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 380
    at TP3.lireFichier(TP3.java:305)
    And my line 305 is: intervalleDiagramme[j] = valeur;
    EDIT2:
    So ok I found my mistake and corrected it. But I want to know is there a way of doing this without setting the size of the array? because sometimes there needs to be 21 values sometimes 19 and sometimes 20....
    If I take out: = new String [21] out I get a NullPointer error...
    Edited by: Ara1992Habs on Dec 13, 2009 7:29 AM
    Edited by: Ara1992Habs on Dec 13, 2009 7:37 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for