Sunday, 15 August 2010

python - java array creation complication -



python - java array creation complication -

being new java after having coded in languages such python , javascript, best way describe issue illustration 1 of 2 languages. start error getting java programme when effort create array directly, such string[] narray = {{'test',1}, {'test', 2}, {'test', 3}} doing gave me illegal initialization error changed array[][] narray = {{'test',1}, {'test', 2}, {'test', 3}} yet giving me "cannot find symbol" error. @ bit of loss how create array directly. in python have narray = [['test', 1], ['test', 2], ['test', 3]]. how define array in java? give thanks you.

how using hashmap particular case :

hashmap<string,integer> map = new hashmap<>(); map.put("foo",1); map.put("bar",2); map.put("baz",3);

if values repeat themselfes consider pair object :

class pair<f,s> { public final f first; public final s second; public pair(f first,s second){ this.first = first; this.second = second; } } // in method list<pair<string,integer>> mylist = new arraylist<>(); mylist.add(new parir("foo",1); mylist.add(new parir("bar",1); mylist.add(new parir("foo",3);

since made jump type safe language might start thinking in one

java python arrays

No comments:

Post a Comment