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

  • Home
  • SEARCH
  • 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 7990187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:56:06+00:00 2026-06-04T12:56:06+00:00

How to Convert ArrayList<> to string … Details: step1: send e-mail address to php

  • 0

How to Convert ArrayList<> to string …

Details:

step1: send e-mail address to php mySql database
step2: if email address match database content, echoed success
step3: retrieved the php echoed value (“success”)
step4: assign the the response to a string phpEchoedVal
step5: compare phpEchoedVal with “success”
step6: write email to sd card

is this one ok
//url = email address

ArrayList nameValuePair = new ArrayList(1);

    nameValuePair.add(new BasicNameValuePair("url", url));

  try {
        //open an httpclient connection

        HttpClient httpclient = new DefaultHttpClient();

        HttpPost httppost = new HttpPost(strLink);

        httppost.setEntity(new UrlEncodedFormEntity(data));


            //response retrieve "success" echoed from server

        ResponseHandler<String> handleResponse = new BasicResponseHandler();

            //converts server response to string.

        String phpEchoVal = httpclient.execute(httppost, handleResponse);


        txtInfo.setText(phpEchoVal);

        String containEmail = txtInfo.getText().toString();



            //compare response from server with local string

            // if successful write email to sd card

        if ((containEmail.equals("success"))){

            //create a new text file

            File myFile = new File("/sdcard/moLarouteReg.txt");

            myFile.createNewFile();

            FileOutputStream fOut = new FileOutputStream(myFile);

            OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);

            myOutWriter.append(containEmail);

            //close writer
            myOutWriter.close();

        fOut.close();

        //Open menu

          Intent openMenu = new Intent("com.molaroute.mu.Menu");

            startActivity(openMenu);

            finish();

        Log.d("test","fileWritten: "+myOutWriter);

        }else {



            ...
        }
   }
  • 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-06-04T12:56:08+00:00Added an answer on June 4, 2026 at 12:56 pm

    For your first question; how to match strings in an array list(containting name value pair objects) to other strings:

        ArrayList<NameValuePair> lst = new ArrayList<NameValuePair>(); //Instantiate arraylist
        lst.add(new BasicNameValuePair("fruit", "apple")); //add entry
        lst.add(new BasicNameValuePair("animal", "monkey")); //add entry
        String strToCompareAgainst = "apple"; //str to compare to for example
        for(NameValuePair valPair : lst) { //foreach loop
            if(valPair.getValue().equals(strToCompareAgainst)) { //retrieve value of the current NameValuePair and compare
                Log.d("login","moooooo"); //success
            }
        }
    

    You can also check if a text contains another text instead of checking for equality.

    String str1 = "I am a success";
    String str2 = "success";
    
    if(str1.contains(str2)) {}  //Evaluates to true, because str1 contains the word "success"
    
    if(str1.equals(str2)) {} //Evaluates to false, because str1 does not hold the same value as str2
    

    Ofcourse you can do alot more, but this should give you the basic idea..

    For your second question:

    HttpClient.execute() returns an HttpResponse.
    From HttpResponse you can call getEntity which returns an HttpEntity
    From HttpEntity you can call getContent which returns an InputStream.

    This InputStream you can convert to string. Example conversion code snippets are widely on the net.

    so the code:

    httpResponse = client.execute(post, _httpContext);
            //Set the response code from the request's responst.
            setResponseCode(httpResponse.getStatusLine().getStatusCode());
            //Retrieve the body of the response.
            entity = httpResponse.getEntity();
    
            if(entity != null) {
                //Retrieve the content from the body.
                _inStream = entity.getContent();
                //Convert the InputStream to String and set the String response to the returned value.
                setStringResponse(IOUtility.convertStreamToString(_inStream));
                //Close the InputStream.
                Log.d(TAG, getStringResponse());
            }   
    

    Note that IOUtility is self written class in this case.
    I think there are other ways to convert a HttpResponse to a string, but this is how I do it.

    _inStream is an InputStream, entity is an HttpEntity, the rest should be self explanatory.

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

Sidebar

Related Questions

How can I convert ArrayList into string[] in C#?
I want to convert ArrayList of Character to String. I read similar thread like
I am trying to convert a String into an ArrayList. For example, my Struts2
I have an ArrayList of Path values. I need to convert it into String
How to convert an ArrayList<Character> to a String in Java? The List.toString method returns
How would I convert List list= new ArrayList(); to String [] profArr= {}; I
I have an ArrayList<String> named listout, I want to convert it to an ArrayList<SelectItem>
Possible Duplicate: Best way to convert an ArrayList to a string I have an
ArrayList arr = new ArrayList(); string abc = What should I do to convert
How do I convert an arraylist into a string of comma delimated values in

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.