-4

Running java in my cgi-bin. Via post request. In my java program, I have the browser output in a string e.g.: name=josh&age=34.... and so on

In my java program String x = "name=joshua";

How can I split this x string by the = delimiter into a hashtable.

My hashtable is Hashtable<String, String>

ankuranurag2
  • 2,300
  • 15
  • 30

1 Answers1

-1

You may try something like this:

// initializes a hashtable for key and value types to be String
Hashtable<String, String> h = 
              new Hashtable<String, String>();
// your string
String x = "name=josh";
// splits the string for "=" delimiter and stores in an array
String[] arrOfStr = x.split("=", 0); 
// Use the 'put' method of Hashtable to insert the 0th element of array as key and 1st element as value
h.put(arrOfStr[0],arrOfStr[1]);
Pingolin
  • 3,161
  • 6
  • 25
  • 40
akg179
  • 1,287
  • 1
  • 6
  • 14
  • Thanks!! If my browser output string contains a bunch of info (key=value) I can use a for loop to the length of the string array and keep putting key=value.. I appreciate it. I'm fairly new to java – Joshua Hollenbeck Apr 24 '19 at 15:03