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 6786435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:14:41+00:00 2026-05-26T17:14:41+00:00

I have a ArrayList that contains values in the form [ann,john]. I want to

  • 0

I have a ArrayList that contains values in the form [ann,john]. I want to convert this ArrayList into a String array in the form {“ann”,”john”}.

How should I do this?

My Android code:

     final Button markabsent = (Button) findViewById(R.id.Button02);
      markabsent.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {

            // Perform action on click
             Toast.makeText(display.this,"You have marked the students absent",Toast.LENGTH_SHORT).show();

             SparseBooleanArray checkedabsent = lView.getCheckedItemPositions();



            for (int i = 0; i < arr2.length; i++) 
            {
                if (checkedabsent.get(i)) 
                {
                    items2.add(arr2[i]);
                    System.out.println(items2);

                }
            }

            Log.d("", "items:");
            for (String string : items2)
            {
                Log.d("string is", string);


            }  
          }
      });  

My Logcat:

     11-10 21:44:00.414: INFO/System.out(2316): [ann, john, ann]
     11-10 21:44:00.414: DEBUG/(2316): items:
     11-10 21:44:00.414: DEBUG/string is(2316): ann
     11-10 21:44:00.414: DEBUG/string is(2316): john

I tried doing everything mentioned in the answers but my logcat just doesn’t seem to imrove

Here is the one giving exceptions:

          11-10 22:14:20.855: INFO/System.out(3322): [Ljava.lang.String;@44eb6ff0
          11-10 22:16:38.186: ERROR/AndroidRuntime(3411): FATAL EXCEPTION: main
          11-10 22:16:38.186: ERROR/AndroidRuntime(3411): java.lang.ClassCastException: [Ljava.lang.Object;
          11-10 22:16:38.186: ERROR/AndroidRuntime(3411):     at com.example.display$2.onClick(display.java:124)
          11-10 22:16:38.186: ERROR/AndroidRuntime(3411):     at android.view.View.performClick(View.java:2408)
          11-10 22:16:38.186: ERROR/AndroidRuntime(3411):     at android.view.View$PerformClick.run(View.java:8816)
          11-10 22:16:38.186: ERROR/AndroidRuntime(3411):     at android.os.Handler.handleCallback(Handler.java:587)

Here is one more:

          11-10 22:14:20.875: DEBUG/string is(3322): ann
          11-10 22:14:20.875: INFO/System.out(3322): [Ljava.lang.String;@44eb7720
          11-10 22:14:20.875: INFO/System.out(3322): [Ljava.lang.String;@44eb7720
          11-10 22:14:20.885: INFO/System.out(3322): [Ljava.lang.String;@44eb7720
          11-10 22:14:20.895: DEBUG/string is(3322): john
          11-10 22:14:20.895: INFO/System.out(3322): [Ljava.lang.String;@44eb7de8
          11-10 22:16:38.186: ERROR/AndroidRuntime(3411):     at com.example.display$2.onClick(display.java:124)
  • 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-26T17:14:42+00:00Added an answer on May 26, 2026 at 5:14 pm

    Use the method “toArray()”

    ArrayList<String>  mStringList= new ArrayList<String>();
    mStringList.add("ann");
    mStringList.add("john");
    Object[] mStringArray = mStringList.toArray();
    
    for(int i = 0; i < mStringArray.length ; i++){
        Log.d("string is",(String)mStringArray[i]);
    }
    

    or you can do it like this: (mentioned in other answers)

    ArrayList<String>  mStringList= new ArrayList<String>();
    mStringList.add("ann");
    mStringList.add("john");
    String[] mStringArray = new String[mStringList.size()];
    mStringArray = mStringList.toArray(mStringArray);
    
    for(int i = 0; i < mStringArray.length ; i++){
        Log.d("string is",(String)mStringArray[i]);
    }
    

    http://developer.android.com/reference/java/util/ArrayList.html#toArray()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ArrayList of type String that contain certain values. I want to
I have a large string that contains fixed value fields, this group of fields
I have an arraylist that contains urls in the form similar to : stackoverflow.com/questions/ask/hello
I have an arraylist that contains items called Room. Each Room has a roomtype
I have an arraylist that gets different type of values in it, 1st value->
I have an ArrayList that I want to use to hold RaceCar objects that
I have an ArrayList<String> that I'd like to return a copy of. ArrayList has
I have a method that returns an IEnumerable<KeyValuePair<string, ArrayList>> , but some of the
I have an ArrayList<String> , and I want to remove repeated strings from it.
I have an ArrayList containing Objects that have a date value. Now I want

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.