Re: Gibberish output is display when returning an array

From: Jose Rubio (spam_at_airphoria.com)
Date: 11/29/03


Date: Sat, 29 Nov 2003 00:52:07 GMT

See below...

"Mohammed Mazid" <kadmazid@hotmail.com> wrote in message
news:7cfd7b4a.0311281428.2e20f8b5@posting.google.com...
> I changed my code as I initially used an Object arrays, I decided to
> use String array instead as I can convert from a date/time to a
> string.
>
> However, when I compiled and run, it displayed a nonsense output.
> Something in the nature of "java.lang.String@28934".

This is not nonsense. That's how Java displays an object.
>
> Here is my latest code fragment.
>
> //This will be passed to the method displayFlights
> String flight1 = "BA123";
>
> String flightArray[] = new String[6];
>
> for (int i = 0; i < flightArray.length; i++)
> {
> out.println("<td>" );
> out.println(displayFlight(flight1));

You're displaying an array, not the actual flight for the first element of
the array. That's why you see the nonsense you called above.

Accoridng to the method below, change the loop above to:

String flightArray[] = displayFlight( flight1 );
for(int i=0; i < flightArray.length; i++ )
{
    out.println( "<td">);
    out.println( flightArray[ i ] );
    out.println( "</td>" );
}

> out.println("</td>" );
> out.println("<br>");
> }
> }
>
> // Return an array of flight details
> public String[] displayFlight(String flightNo)
> {
> String[] flight = new String[6];
> SetupFlightDB flightDB = new SetupFlightDB();
> FlightInformation flightInfo = flightDB.flightDetails(flightNo);
>
> flight[0] = flightInfo.getFlightNo();
>
> java.sql.Date flightDate = flightInfo.getFlightDate();
> String dateString = String.valueOf(flightDate);
> flight[1] = dateString;
>
> flight[2] = flightInfo.getDestination();
>
> java.sql.Time depTime = flightInfo.getDepTime();
> String dTimeString = String.valueOf(depTime);
> flight[3] = dTimeString;
>
> java.sql.Time arrTime = flightInfo.getArrTime();
> String aTimeString = String.valueOf(arrTime);
> flight[4] = aTimeString;
>
> flight[5] = flightInfo.getAirline();
> return flight;
> }
>
> Basically I am trying to achieve something like this - pass a string
> to the method so that from a DB table, it displays all the records
> from the columns in an array style.
>
> Can anyone suggest me some improvement to the above.
>
> Thank you.

Hope it helps.

-- 
Jose Rubio
Lead Consultant
Airphoria
http://www.airphoria.com


Relevant Pages

  • Re: passing a string to a dll
    ... Joe, I really appreciate you taking the time to demonstrate this. ... sure how I would implement indexing it for random alphanumeric codes. ... I might handle the array. ... I actually have been wondering if I could use a second string ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... I might handle the array. ... I actually have been wondering if I could use a second string ... look at insertion cost, organization cost, and search cost. ...
    (microsoft.public.vc.mfc)
  • Re: Array Type Mismatch
    ... Dim resultAs String ... I am still somewhat confused as to why nothing is stored in the array. ... Public Function TextBoxGetLine(....arguments... ...
    (microsoft.public.access.formscoding)
  • Re: NumberFormatException:please help me......!!!
    ... Record that has string and array of double as members) and file could ... follows it on a line of the input file, you could use the String as a key to ... contain String representations of doubles. ...
    (comp.lang.java.programmer)
  • Help in Spanish translation of the description of UDFs
    ... functions of minimum / maximum values among elements of an array column. ... GETALLWORDS- Inserts the words from a string into a global dimensioned ... WORDTRAN- Searches a character string for occurrences of a first word, ... ARRAYSUM- Returns the sum of all or a specified range of numeric (and/or ...
    (microsoft.public.fox.helpwanted)