Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Check for duplicate key in hashmap

715138Jun 15 2012 — edited Jun 18 2012
Hi All,

I have a String array which has underscore separated values.

e.g :String str[]=new String[]{"batchId+bemId_only_bentype_ben_id","batcytrd_only_bentype_ben_id"};

now we have to traverse this array and and store the value before underscore as a key for hashmap and rest as value for hashmap.

Here "batchId+bemId" will be as a key and "only_bentype_ben_id" will be value .similarly for second array element the key will be "batcytrd" and value will be "only_bentype_ben_id".

How to achive this .I am not able to split the element as key and value .

My sample code is like this :This is not complete code :

import java.util.StringTokenizer;



public class DuplicateCheck {

public static void main(String[] args) {
String str[]=new String[]{"batchId+bemId_only_bentype_ben_id","batchId+bemId_only_bentype_ben_id"};
String str1;
StringTokenizer st2;
for (int i=0;i<str.length;i++){
str1=str;
st2 = new StringTokenizer(str1, "_");

while(st2.hasMoreTokens()) {
String key = st2.nextToken();
System.out.println(key );
}
}
}
}


Thanks
Sumit

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jul 16 2012
Added on Jun 15 2012
9 comments
313 views