Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6019667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:27:17+00:00 2026-05-23T03:27:17+00:00

Which one is faster to have database key as String or as Long? If

  • 0

Which one is faster to have database key as String or as Long? If the difference is micro seconds, it does not matter to our application. The table has thousands records/rows. If Long is faster, how to convert a String into Long, are there some Java API so that unique String could be converted to unique long?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:27:17+00:00Added an answer on May 23, 2026 at 3:27 am

    Which one is faster to have database key as String or as Long?

    It is very very likely that a long is faster than a String. For one thing, processors can deal with values of type long “naturally”, while a String has to be manipulated via software. Also, a string will likely occupy more memory than a long value which means the caches are under more stress and more data has to be loaded from / saved to disk.

    If the difference is micro seconds, it does not matter to our application. The table has thousands records/rows.

    So it depends on the operations. If you

    If Long is faster, how to convert a String into Long, are there some Java API so that unique String could be converted to unique long?

    You can derive an int from a String using it’s hash code. This the ints you will get from this method will be well distributed within the allowed range, but are not guaranteed to be unique. Generally it is not possibly to derive a unique int from a string, because there are strictly more strings than long.

    Just imagine you build a giant table holding the decimal representation of all long values. Now there is a trivial long <-> string mapping between the two. But this table still does not contain the string “hello world”, and there are no more long’s left you could use to represent this string.

    Generally my advice is: If your source data is naturally of type string, use that and let the database do the optimizations. A table holding “thousands” of entries won’t be a problem for any current database. Maybe you can help performance by creating clever indexes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three one-dimensional arrays. The task is to store the numbers which exist
I have a couple of needs in my application for which working on edge
If I have a set number of String 's that I want to check
I have used Log4j and JDK Logger both for logging purpose, so i find
So I have a MySQL query that is being created dynamically based on parameters
Background I'm making a canvas game which assumes the user to be using a
I have a fairly complex procedure that currently takes about 1:30 (min:sec) to complete.
Often, people say that it is better to say s.Length == 0 instead of
Hello yeah I'm asking this question a second time, sorry about that but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.