标记哈希映射中的值 [英] To tokenize the values in a hashmap
问题描述
我有一个关键字长度和值为String的地图。
1:BusinessPartner.name1,BusinessPartner。地图的值是从数据库中获得的,格式如下。 name2,BusinessPartner.name3,BusinessPartner.name4
2:BusinessPartner.name1,BusinessPartner.name2,BusinessPartner.name3
6:ADDRESS.addressline1,ADDRESS.addressline2,ADDRESS.addressline3
其中1,2,6是键。
我需要标记化键1的字符串,结果应该是
Businesspartner,其他值应该是name1,name2,name3,name4。
我这样做是因为我需要将这些值放到另一个映射中作为
映射(name1,name2,name3,name4)>
我可以拆分字符串,但如何将Businesspartner作为其他实体的共同价值
有谁可以告诉我如何做到这一点
谢谢
这件作品适合你的riquierment吗?
public class Tokenize {
static Long keysFromDB [] = {1L,2L,6L};
static String stringsFromDB [] = {
BusinessPartner.name1,BusinessPartner.name2,BusinessPartner.name3,BusinessPartner.name4,
BusinessPartner.name1,BusinessPartner.name2,BusinessPartner.name3 ,
ADDRESS.addressline1,ADDRESS.addressline2,ADDRESS.addressline3};
@Test
public void tokenize(){
//使用链接的hashmap保存订单
Map< Long,Set< String>> tokenized = new LinkedHashMap< Long,Set< String>>();
int c = 0;
for(Long key:keysFromDB){
//使用链接的哈希集保存订单
Set< String> record = new LinkedHashSet< String>();
String splitedDBStrings [] = stringsFromDB [c ++]。split(\\。|,);
System.out.println(List:+ Arrays.asList(splitedDBStrings));
for(String s:splitedDBStrings){
record.add(s);
}
System.out.println(Set:+ record);
tokenized.put(key,record);
}
System.out.println(tokenized);
}
}
I have a map whcih has the key value as long and value as String. The values of the map are obtained from the db and it is in the below format.
1: BusinessPartner.name1,BusinessPartner.name2,BusinessPartner.name3,BusinessPartner.name4
2: BusinessPartner.name1,BusinessPartner.name2,BusinessPartner.name3
6: ADDRESS.addressline1,ADDRESS.addressline2,ADDRESS.addressline3
where 1,2,6 are the keys.
I need to tokenize the strings that is for the key 1 the result should be Businesspartner and the other values should be name1,name2,name3,name4. I am doing this because i need to put these values into an another map as Map(name1,name2,name3,name4)> I can split the string but how to take Businesspartner as a common value for the other entities
Can anybody tell me how to do this
Thanks
would this work for your riquierment ?
public class Tokenize {
static Long keysFromDB[] = {1L, 2L, 6L};
static String stringsFromDB[] = {
"BusinessPartner.name1,BusinessPartner.name2,BusinessPartner.name3,BusinessPartner.name4",
"BusinessPartner.name1,BusinessPartner.name2,BusinessPartner.name3",
"ADDRESS.addressline1,ADDRESS.addressline2,ADDRESS.addressline3"};
@Test
public void tokenize() {
// use linked hashmap to preserve the order
Map<Long, Set<String>> tokenized = new LinkedHashMap<Long, Set<String>>();
int c = 0;
for(Long key : keysFromDB) {
// use linked hashset to preserve the order
Set<String> record = new LinkedHashSet<String>();
String splitedDBStrings[] = stringsFromDB[c++].split("\\.|,");
System.out.println("List: " + Arrays.asList(splitedDBStrings));
for(String s : splitedDBStrings) {
record.add(s);
}
System.out.println("Set: " + record);
tokenized.put(key, record);
}
System.out.println(tokenized);
}
}
这篇关于标记哈希映射中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!