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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:06:19+00:00 2026-05-19T17:06:19+00:00

The following code is in PHP. I want to do the same in Java.

  • 0

The following code is in PHP. I want to do the same in Java. Please tell me how do I generate this type of array or collection in Java. I need this to response to JSON autocomplete.

<?php
$q = strtolower($_GET["q"]);
if (!$q) return;
$items = array(
 "Peter Pan"=>"peter@pan.de",
 "Molly"=>"molly@yahoo.com",
 "Forneria Marconi"=>"live@japan.jp",
 "Master Sync"=>"205bw@samsung.com",
 "Dr. Tech de Log"=>"g15@logitech.com",
 "Don Corleone"=>"don@vegas.com",
 "Mc Chick"=>"info@donalds.org",
 "Donnie Darko"=>"dd@timeshift.info",
 "Quake The Net"=>"webmaster@quakenet.org",
 "Dr. Write"=>"write@writable.com"
);

$result = array();
foreach ($items as $key=>$value) {
 if (strpos(strtolower($key), $q) !== false) {
  array_push($result, array(
   "name" => $key,
   "to" => $value
  ));
 }
}
echo json_encode($result);
?>

Update:

I want java version of this PHP code because this code is returning in JSON format. In

{name=>"Peter Pan",
 to=>"peter@pan.de";
.....}

As you see this:-

array_push($result, array(
   "name" => $key,
   "to" => $value
  ));

Which can be handled by this jQuery code:-

$('#inputItem').autocomplete('<c:url value="/json/itemautocomplete.do" />', {
            multiple: true,
            mustMatch: true,
            autoFill: true,
            highlight: false,
            scroll: true,
            dataType: "json",
            parse: function(data){
                var array = new Array();
                for(var i = 0; i<data.length; i++){

                    array[array.length] = {data: data[i], value: data[i].name, result: data[i].name};
                                        }
                return array;


            }

        });

This plugin is available on this url

I know how to handle JSON data by using JSONArray in $.getJSON jQuery method. But that thing is not working in this case. I think I need to format my data as I described above in this answer so that this jQuery autocomplete plugin can understand the data. Please tell me how can I get this…

  • 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-19T17:06:19+00:00Added an answer on May 19, 2026 at 5:06 pm

    In Java, you would use a Map<String, String>:

    Map<String, String> items = new HashMap<String, String>();
    items.put("Peter Pan", "peter@pan.de");
    
    String petersAddress = items.get("Peter Pan");
    

    You can iterate through the keyset:

    for ( String key : items.keySet() ) {
      if ( key.toLowerCase().startsWith(input) ) {
         //add to list of potential matches
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why is the following code crashing in PHP? $normal_array = array(); $array_of_arrayrefs = array(
currently I have following code: home.php <form name='myformname' id='myformid'> <input type='text' name='mytext1' value='abc'> <input
The following PHP code snippet uses GD to resize a browser-uploaded PNG to 128x128.
I am running following PHP code to interact with a MS Access database. $odbc_con
I am using following PHP code to connect to MS Access database: $odb_conn =
I have the following php code, which has been snipped for brevity. I am
I'm detecting @replies in a Twitter stream with the following PHP code using regexes.
I have the following code: http://www.nomorepasting.com/getpaste.php?pasteid=22615 Which is called by the javascript mentioned in
I have to following code: http://www.nomorepasting.com/getpaste.php?pasteid=22987 If PHPSESSID is not already in the table
I am using the following code: <?php $stock = $_GET[s]; //returns stock ticker symbol

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.