tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Java Scripting > BeanShell > Hash table

Hash table 

BeanShell is a small, free, embeddable Java source interpreter with object scripting language features, written in Java. BeanShell is a natural scripting language for Java. This requires the library bsh-2.0b4.jar to be in classpath. The following example shows creating hashtable in beanshell script.

File Name  :  
/BEAN_SHELL001/config/hash_table.bsh 
   
//Standard Typed Syntax
Hashtable ht = new Hashtable();
ht.put("ONE"1);
ht.put("TWO"2);

print(ht);
print(ht.get("TWO"));

//Loosely Typed Syntax
ht2 = new Hashtable();
ht2.put("ONE"1);
ht2{"TWO"2

print(ht2);
print(ht2{"ONE"});
   

File Name  :  
com/bethecoder/tutorials/bean_shell/HashtableTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.bean_shell;

import java.io.InputStreamReader;

import bsh.EvalError;
import bsh.Interpreter;

public class HashtableTest {

  /**
   @param args
   @throws EvalError 
   */
  public static void main(String[] argsthrows EvalError {
    Interpreter interpreter = new Interpreter();  
    InputStreamReader reader = new InputStreamReader(
        HashtableTest.class.getClassLoader()
        .getResourceAsStream("hash_table.bsh"));
    
    interpreter.eval(reader);
  }

}
   

It gives the following output,
{TWO=2, ONE=1}
2
{TWO=2, ONE=1}
1


                    Print

   



Books Recommendation

 
 
bl  br