简体   繁体   English

为Java应用程序存储本地数据

[英]Storing local data for java application

My friend challenged me to make a java application just like the "love test" mobile app. 我的朋友向我提出挑战,要求我开发一个Java应用程序,就像“爱情测试”移动应用程序一样。 If you aren't familiar with this app you input two names(yours and someone else's) and it gives you the percentage of "compatibility". 如果您不熟悉此应用程序,则输入两个名称(您和其他人的名称),它会为您提供“兼容性”的百分比。 I want the random percentages to get saved so when they input the same names again it will display the same number. 我希望保存随机百分比,以便当他们再次输入相同的名称时,它将显示相同的数字。

How about computing hash of the strings and computing a percentage based on some formula of your own using hash ? 如何计算字符串的哈希并使用哈希根据您自己的某些公式计算百分比? You get same value every time and no need to store value also. 您每次都能获得相同的价值,也无需存储价值。

Use a Map<String, Double> where the key is the concatenation of the names in alphabetic order, separated by a special character (ie & ), and the value is the percentage. 使用Map<String, Double> ,其中键是名称的字母顺序串联,以特殊字符(即& )分隔,值是百分比。

In case you have to persist this data, you can serialize the Map, store it on disc, and recover it when you need it again. 如果必须保留这些数据,可以序列化Map,将其存储在磁盘上,并在需要时恢复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM