servlet resopnse data for autocomplete

Posted by shams haque on Stack Overflow See other posts from Stack Overflow or by shams haque
Published on 2011-01-28T14:31:37Z Indexed on 2011/01/29 7:25 UTC
Read the original article Hit count: 290

Filed under:
|

Hello experts,

Following code is in php. i want to do 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"=>"[email protected]",
 "Molly"=>"[email protected]",
 "Forneria Marconi"=>"[email protected]",
 "Master Sync"=>"[email protected]",
 "Dr. Tech de Log"=>"[email protected]",
 "Don Corleone"=>"[email protected]",
 "Mc Chick"=>"[email protected]",
 "Donnie Darko"=>"[email protected]",
 "Quake The Net"=>"[email protected]",
 "Dr. Write"=>"[email protected]"
);

$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);
?>

© Stack Overflow or respective owner

Related posts about java

Related posts about autocomplete