list - How to sort values coming from bean using hasmap in java -
hi new here , on task, dont have experience working hashmap
actually receiving string next value
string value1 = "da45:1|da33:2|da25:3";
actually have
map<integer, string> value1 = new hashmap<integer, string>();
i need parse these data , generating map such priority key , device name value example :
key1 ----- > da45
key2 -----> da33
key3 -----> da25
please notice need split ":","the number" , pipe
thanks in advance helping me
import java.util.hashmap; import java.util.map; public class main { public static void main(string[] args) { map<integer, string> map = new hashmap<integer, string>(); string value1 = "da45:1|da33:2|da25:3"; string[] x = value1.split("\\|"); integer key; string value; (int = 0; < x.length; i++) { string[] y = x[i].split(":"); value = y[0]; key = integer.parseint(y[1]); map.put(key, value); } } }
in end of code snippet, map fullfiled information.
please choose better names variables, example.
Comments
Post a Comment