将字符串或数字倒序输出
将字符串或数字倒序输出,以使这些呈散列分布,用于作为hbase rowkey的一部分,避免region的读写热点
public class StringUtil { public static void main(String[] args) { long start = System.currentTimeMillis(); for (int i = 0; i < 10; i++) { System.out.println(reverseLong(78945612399l)); } System.out.println(System.currentTimeMillis() - start); } /** * 将一个数字倒序输出, 先将数字转换为字符串,然后利用reverse函数 * * @param num * @return */ public static String reverseNumberByStr(long num) { StringBuffer res = new StringBuffer(Long.toString(num)); res.reverse(); return res.toString(); } /** * 将一个long型数字倒序输出 * * @param n * @return */ public static long reverseLong(long n) { long reverse = 0; long part = 0; while (n > 0) { part = n % 10; reverse = reverse * 10 + part; n /= 10; } return reverse; } /** * 将字符串倒序输出,使用reverse函数,效率很高 * * @param str * @return */ public static String reverseString(String str) { StringBuffer res = new StringBuffer(str); res.reverse(); return res.toString(); } /** * 将字符串倒序输出,使用charAt,效率不及reverseString * * @param str * @return */ public static String reverseStrByCharAt(String str) { String res = ""; for (int i = str.length() - 1; i > -1; i--) { res += str.charAt(i); } return res; } }

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
ZeroCopyLiteralByteString cannot access superclass
问题描述 在HBase上运行MapReduce作业时,报如下异常:IllegalAccessError: class com.google.protobuf.HBaseZeroCopyByteString cannot access its superclass com.google.protobuf.LiteralByteString 使用HBase环境如下:CDH5.0.1, HBase版本:0.96.1 问题原因 This isssue occurs because of an optimization introduced inHBASE-9867that inadvertently introduced a classloader dependency. This affects both jobs using the-libjarsoption and "fat jar," jobs which package their runtime dependencies in a nested lib folder. 这个问题的发生是由于优化了HBASE-9867引...
- 下一篇
HBase源码阅读资源
HBase MemStoreFlusher 虽与最新版0.98.7的实现已经有差异,但分析的比较好 MemeStoreFlusher在HRegionServer类中初始化。 HRegionServer实现了Runnable接口,在run方法中针对MemeStoreFlusher进行了初始化 privatevoidinitializeThreads()throwsIOException{ //Cacheflushingthread. this.cacheFlusher=newMemStoreFlusher(conf,this); ... } 启动: this.cacheFlusher.start(uncaughtExceptionHandler); interrupt: if(this.cacheFlusher!=null)this.cacheFlusher.interruptIfNecessary();
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Docker安装Oracle12C,快速搭建Oracle学习环境
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- Eclipse初始化配置,告别卡顿、闪退、编译时间过长
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- 设置Eclipse缩进为4个空格,增强代码规范
- CentOS7,CentOS8安装Elasticsearch6.8.6
- CentOS8编译安装MySQL8.0.19