有一个业务场景,会随机出现一个字母或数字(a到z或0到9),我需要将这个字母或数字平均映射到两个值上(比如:01和02),用Java该如何实现?最好有代码,谢谢
闭关修行中......
I don’t understand what the poster meant. Is it fixed mapping or random mapping? Just make a table for fixed mapping
Map<Charactor, String> mapping = new HashMap<Charactor, String>(); mapping.put('a', "01"); mapping.put('b', "02"); mapping.put('c', "01"); mapping.put('d', "02"); // 或者for循环打表也一样 String map(char src) { return mapping.get(src); // 省略了范围判断 }
I don’t understand what the poster meant. Is it fixed mapping or random mapping? Just make a table for fixed mapping