Question: The basic idea of what I want to achieve is to make a comparison between the current Android system date and an existing date in a SQlite database.

The idea is to 1.) If the database does not contain contain a entry with today's date, then allow new entry

2.) If the database already contains an entry from today's date, then revoke entry and output error message.

My DBAdapter currently has a method that does the following:

```
public Cursor getDate(String date) {
String where = KEY_DATE + "=" + date;
Cursor c =  db.query(true, DATABASE_TABLE, ALL_KEYS, 
                where, null, null, null, null, null);
if (c !=null) {
    c.moveToFirst();
}
return c;
}

```

and the method i'm using to make the comparison is:

```
public void addRecord (View view){
    db.open();
    Cursor cursor = db.getDate(dateString);

    if (cursor.moveToFirst()){
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Date"); 
        builder.setMessage("Entry for today exists, would you like to update this instead?"); builder.setPositiveButton("OK", null);
        @SuppressWarnings("unused")
        AlertDialog dialog = builder.show();
        db.close();
    }
    else{

Do other work..

```

both Date's used for comparison is formatted using this code:

```
long longDate = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateString = sdf.format(longDate);

```

where I'm simply calling 'dateString'

My trouble is that it doesn't perform the correct checks and skips my else statement completely even tho i know there is an existing 'date' in the database. Is my SQL statement correct?

Answer: 
When you call `map` on a `String` it is wrapped with `WrappedString` which extends `AbstractSeq[Char]`. Therefore, when you call `map` it is as if you are doing so on a `Seq` of `Char` not a `Seq` of `String`.

See the link below for the code <https://github.com/scala/scala/blob/v2.10.2/src/library/scala/collection/immutable/WrappedString.scala>

The code below splits by whitespace and returns the size, a word counter.

```
val file = "Some test data"
file.split("\\s+").size

```

To get a count of the number of times each word in the string appears.

```
val file = "Some test data test"
println(file.split("\\s+").toList.groupBy(w => w).mapValues(_.length))

```
I found out that the code is perfect! Just because I was running it on Spark, the answer was kept in lazy RDD file that I needed to collect it somehow. Therefore, I saved it to a text file and problem solved! Here is the code:

file.flatMap(line=>line.split(" ")).map(w=>(w,1)).reduceByKey(*+*).saveAsTextFile("OUT.txt")

Thanks.