Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7183227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:56:12+00:00 2026-05-28T17:56:12+00:00

I am trying to log the contents of an arraylist. The arraylist contains a

  • 0

I am trying to log the contents of an arraylist. The arraylist contains a custom object with 4 parameters. When I execute the following code I get the following log. what i want is a string of [name,class,thirty,ninety],[name,class,thirty,ninety], etc

Custom Object Class:

public class Data {
        String NAME;
        String CLASS;
        String THIRTY;//this is the thirty day supply
        String NINETY;//this is the ninety day supply

    public Data(){
        super();
    }
    public Data(String NAME, String CLASS, String THIRTY, String NINETY){
        super();
        this.NAME = NAME;
        this.CLASS = CLASS;
        this.THIRTY = THIRTY;
        this.NINETY = NINETY;
    }

    }

Activity:

ArrayList<Data> array = new ArrayList<Data>();

Cursor c = mDBHelper.getReadableDatabase().query(Constants.K_Table, null, Constants.Name +"=?", new String[] {SEARCH}, null, null, null);

            startManagingCursor(c);
            if (c.moveToFirst()){

            NAME = c.getString(c.getColumnIndex(Constants.Name));
            CLASS = c.getString(c.getColumnIndex(Constants.Class));
            THIRTY = c.getString(c.getColumnIndex(Constants.Month));
            NINETY = c.getString(c.getColumnIndex(Constants.Three_Month));

            array.add(new DrugData(NAME, CLASS, THIRTY, NINETY));
            Log.d(TAG, "array contains: "+ array.toArray().toString());
            }while(c.moveToNext());

Log:

01-28 22:31:44.742: D/Activity(23656): the array contains: [com.Data@40552050]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:56:13+00:00Added an answer on May 28, 2026 at 5:56 pm

    To achieve your objective to print String of object you have to do two things in your code.
    1) Override toString method.

    @Override
    public String toString() {
        return "Data [NAME=" + NAME + ", CLASS=" + CLASS + ", THIRTY=" + THIRTY
                + ", NINETY=" + NINETY + "]";
    }
    

    2) ArrayList<Data> array is collection of Data objects. You have to specify which object you want to print. You can do that in two ways.

        int index = 0;// Index of object in the ArrayList
        Log.i("Data",array.get(index).toString());//Preferred Method to get object
        Log.i("Data",array.toArray()[index].toString());
    

    You can loop through your array to print all Data objects like this

        for (Data data : array) {
            Log.i("Data",data.toString());
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to log the contents of an object to a text file.
I am trying to log a method's parameters by using reflection. I read the
I am trying to log the contents of an http request, using an IHttpModule
I'm Trying to Write Logs to Custom Log.txt File on Android File using this
I'm trying to send the contents of UITextView or UITextField as parameters to a
I'm trying to hold a set of ID's in an ArrayList I then want
I'm trying to log the contents of the HttpServletRequest attributes collection. I need to
I am trying to log some input values into an array via jquery and
Because I am a newbie I am trying to log out any errors that
Using Forms Authentication in ASP.NET MVC when trying to log back into a site,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.