Short and Sweet programms
word(hashtable.toString) to hash table
This mehtod can use to create a hash table from a word which genarate from hashtable.toString().
public static Hashtable getHashtable(String word) {
Hashtable hTable = new Hashtable();
if (word != null) {
word= word.replace('{', ' ');
word= word.replace('}', ' ');
word= word.trim();
try{
StringTokenizer st = new StringTokenizer(word, "=,");
while (st.hasMoreTokens()) {
String key = st.nextToken();
String val = st.nextToken();
hTable.put(key.trim(), val.trim());
}
}catch(Exception e){
return hTable;
}
}
return hTable;
}
Sample program for Convert Csv to String Array
class CvsToString{
public static void main(String[] args) {
int i,comInd=0,newComInd;
String id= null;
String name= null,newStr;
String sMsg ="10,ert,12031985,101,st1,st2,twn,10,";
String[] arr = new String[10];
if(sMsg != null){
for(i=0;i<8;i++){
//System.out.println("comid"+comInd);
newComInd=sMsg.indexOf(',',comInd);
//System.out.println("newid"+newComInd);
id= sMsg.substring(comInd,newComInd);
arr[i]=id;
//System.out.println("id "+id);
newStr=sMsg.substring(newComInd);
//System.out.println("nwStr "+newStr);
sMsg=newStr;
comInd=1;
}
}
for(i=0;i<8;i++){
System.out.println(arr[i]);
}
}
}
This mehtod can use to create a hash table from a word which genarate from hashtable.toString().
public static Hashtable getHashtable(String word) {
Hashtable hTable = new Hashtable();
if (word != null) {
word= word.replace('{', ' ');
word= word.replace('}', ' ');
word= word.trim();
try{
StringTokenizer st = new StringTokenizer(word, "=,");
while (st.hasMoreTokens()) {
String key = st.nextToken();
String val = st.nextToken();
hTable.put(key.trim(), val.trim());
}
}catch(Exception e){
return hTable;
}
}
return hTable;
}
Sample program for Convert Csv to String Array
class CvsToString{
public static void main(String[] args) {
int i,comInd=0,newComInd;
String id= null;
String name= null,newStr;
String sMsg ="10,ert,12031985,101,st1,st2,twn,10,";
String[] arr = new String[10];
if(sMsg != null){
for(i=0;i<8;i++){
//System.out.println("comid"+comInd);
newComInd=sMsg.indexOf(',',comInd);
//System.out.println("newid"+newComInd);
id= sMsg.substring(comInd,newComInd);
arr[i]=id;
//System.out.println("id "+id);
newStr=sMsg.substring(newComInd);
//System.out.println("nwStr "+newStr);
sMsg=newStr;
comInd=1;
}
}
for(i=0;i<8;i++){
System.out.println(arr[i]);
}
}
}