Home > Programming > Using Java Api in Scala

Using Java Api in Scala

I love doing things on the console/shell and whenever I use Java I love to use the java.util.Scanner class to read from the shell. I was working on an SQL project and had to put a single quote at the beginning of a line and single quote followed by comma at the end. I had over 1000+ lines of data to do so. Instead of using find-replace I started writing my code in Java to do that for me. Then I thought why not use Scala scripting. So I began coding in Scala and then I realized I don’t know what library to use in Scala, but I knew we could use java library in Scala. How cool! So here is how I did it (it is not a script after all as I did use an object).

import java.util.Scanner
object InsertString {
def main(args: Array[String]){
val in = new Scanner(System.in)
while ( in.hasNext ){
val x = in.next
println(“‘” + x + “‘,”)
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: