Search code examples
javacase-sensitive

Building case insensitive movie database


I'm doing a university assignment, where I have to build 4 classes, one of which is a interface.

I need to make sure that strings are not case sensitive e.g. "the godfather", "The godfather", "The Godfather", are treated as the same movie. how can I do this?


Solution

  • Adding to what Aaron said, I would like to point out that it really depends on your implementation. By the way I am seeing it, you are tasked with creating a "search" function which searches through the database. Properly storing the movie names would be saving them in their actual format ("The Godfather") but when a search is initiated you want to match the search query with the database using the String .equalsIgnoreCase() function. For example:

    String a = "The Godfather"
    String b = "the godfather"
    String c = "The Godfather"
    String d = "thE GoDfaTher"
    System.out.println(a.equalsIgnoreCase(b)); // Outputs true
    System.out.println(a.equalsIgnoreCase(c)); // Outputs true
    System.out.println(a.equalsIgnoreCase(d)); // Outputs true
    System.out.println(a.equals(b)); // Outputs false