Creating array of hash maps
hi,
I tried creating an array of hash maps in my application .
but it continued to give me problem
can any of u help me in this regard.
thank you
int SIZE=...;
HashMap[] maps=new HashMap[SIZE];
for(int i=0; i<maps.length; i++){
maps=new HashMap();
Gil
Or, for a purposely misleading solution...int SIZE=...;
HashMap[] maps = new HashMap[SIZE];
java.util.Arrays.fill(maps, new HashMap());
Similar Messages
-
How to create a dicitionary using hash map.
Hi All,
I want to create a dictionary using hash map where in i can add new words and there meaning. I have written some code But I am not happy with this. Can you suggest me how to add the words and there meanings to the hash map.
I am not able to add the words and there meaning to the hash map.
for this i tried creating a dictionary class.
// Using hashmap
import java.util.*;
public class Dictionary
public static void main(String[] args)
// Create a hash map
HashMap hm = new HashMap();
// put elements to the map
hm.put("Abode: ", "Home");
hm.put("Balance: ", "An intrument to measure or weigh");
hm.put("Car: ", "Automobile");
hm.put("Dinner: ","Last meal of the day generally had after evening and before sleeping");
hm.put("Embossed: ", "Engraved kind");
Set set = hm.entrySet();
Iterator i = set.iterator();
while (i.hasNext())
Map.Entry me = (Map.Entry) i.next();
System.out.print(me.getKey() + ": ");
System.out.println(me.getValue());
System.out.println();
}This is the other Dictionary class which i created.
public class Main_Dictionary
public static void main(String[] args)
Content_Dictionary cd = new Content_Dictionary();
cd.getContent_Dictionary("Abode", "Home");
cd.displayValues();
class Content_Dictionary
String word, meaning;
Content_Dictionary()
word = "a";
meaning = "b";
Content_Dictionary(String x, String y)
word = x;
meaning = y;
void getContent_Dictionary(String w, String m)
word = w;
meaning = m;
void displayValues()
System.out.print(word + ": ");
System.out.println(meaning);
}If i create an interface containing all the words and there meaning
public interface Words_Dictionary
String Abode = "Home";
String Dark = "Lacking brightness";
String Balance = "An intrument to measure or weigh";
String Car = "Type of Automobile";
String Dinner = "Last meal of the day";
String Embossed = "Engraved kind";
String Adroit = "SkillFul";
}and then create a another class which implements this interface, but how should i add these words and there meaning in the hashmap.I tried creating word document but i was unable to
figure out how to do the operations on the word
document and its content,
So This is what i could come up with, i just created
one class Dictionary , now I am able to search for
the meaning of the word specified by me, and I am
able to print all the words and there meanings added
to the hashmap, but i am not able to figure out how
to add a new word and the meaning in the hashmap and
how to find is a word is there or not...May I suggest a slightly different approach?
Do not create a String ==> String mapping, but a String ==> List<String> mapping. And do NOT place everything inside your main method.
Here's a small demo:
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
public class Dictionary {
private Map< String, List<String >> dictionary;
public Dictionary() {
dictionary = new HashMap< String, List<String >>();
public void addWord(String base, String meaning) {
List<String> allMeanings = dictionary.get(base);
if(allMeanings == null) { // if null, there is no entry mapped to 'base' yet: create a new one
List<String> newMeanings = new ArrayList<String>();
newMeanings.add(meaning);
dictionary.put(base, newMeanings);
} else {
allMeanings.add(meaning);
public List<String> search(String base) {
// your code here
return null;
// ... other methods ...
public String toString() {
StringBuilder strb = new StringBuilder();
for(Map.Entry< String, List<String >> e : dictionary.entrySet()) {
strb.append(e.getKey());
strb.append(" : ");
strb.append(e.getValue());
strb.append('\n');
return strb.toString();
public static void main(String[] args) {
Dictionary dict = new Dictionary();
dict.addWord("Abode", "Home");
dict.addWord("Abode", "House");
dict.addWord("Car", "Automobile");
dict.addWord("Car", "Vehicle");
System.out.println(dict);
}Good luck. -
Is it possible to insert a value in a hash map at a perticular index ?
Hello Techies,
I have a drop down list which is used to select a contry name. I also contains " All " option which is used to select all countries.
I am using HashMap for this drop down list for getting corresponding value.
Now, my requirement is the " All " should display as the first in the drop down list. Hash map didn't support bcoz it is in sorted order,
Can any one help me with alternative solution ?
Thanks in advance.
JavedNow, my requirement is the " All " should display as the first in the drop down
list. Hash map didn't support bcoz it is in sorted order,Rather HashMap doesn't support this because according to the first paragraph
of its API documentation "This class makes no guarantees as to the order of the
map; in particular, it does not guarantee that the order will remain constant over
time".
Is the drop down list a JComboBox? If so how are you using the hash map?
And can't you just create an array from the hash map's keys, putting "All" at the
start? -
Hi All ,
I i have the data in below format:
Name Age Skill Company
Vass 21 Java Zylog
Samy 24 PB HP
Lee 18 ADF CTS
Reng 16 Java Info
I converted this data into java collections List<Hash Map> like this.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
public class HashMapDemo {
public static void main(String[] args) {
// Create a hash map
List<HashMap> list = new ArrayList<HashMap>();
HashMap hm = new HashMap();
hm.put("Name", new String("Vass"));
hm.put("Age", new Integer(21));
hm.put("Company", new String("Zylog"));
hm.put("skill", new String("Java"));
list.add(hm);
HashMap hm1 = new HashMap();
hm1.put("Name", new String("Samy"));
hm1.put("Age", new Integer(24));
hm1.put("Company", new String("HP"));
hm1.put("skill", new String("PB"));
list.add(hm1);
HashMap hm2 = new HashMap();
hm2.put("Name", new String("Lee"));
hm2.put("Age", new Integer(18));
hm2.put("Company", new String("CTS"));
hm2.put("skill", new String("ADF"));
list.add(hm2);
HashMap hm3 = new HashMap();
hm3.put("Name", new String("Reng"));
hm3.put("Age", new Integer(16));
hm3.put("Company", new String("Info"));
hm3.put("skill", new String("Java"));
list.add(hm3);
Iterator i = list.iterator();
while (i.hasNext()) {
System.out.println(i.next());
} As per data (table format) i want to sort the data in Column level
how can i to achieve ?.
List<HashMap> is type of collection is help to me?
Any idea?
Thanks,
Vass LeeCheck out Comparator, and use Google to find examples on how to use it.
http://download.oracle.com/javase/6/docs/api/java/util/Comparator.html
Still sorting a collection of hashmaps is a bit odd design though. I think you want to create a simple class with properties in stead of a HashMap, then implement Comparable on that class. -
Declaring and creating fields in Hasp map
I have a Club class with 2 fields
allMeetings
allMembers.
allMeetings must be implented as a HashMap and the value for allMeeting will be a RaceMeeting( have created this class already) objects and the key value will be a String.
The question is how will I declare and create the fields in the Hash map> The question is how will I declare and create the
fields in the Hash map
The Java� Tutorial - Java� Collections Framework -
Hi,
[b] how to sort hash map contains integer objects,
HashMap map=new HashMap();
map.put("1",new Integer("1"));
map.put("2",new Ineger("2")):
map.put("3",new Ineger("3")):
map.put(4,new Integer("4"));
map.put("10",new Integer("10"));
map.put("11",new Integer("11"));
map.put("12",new Integer("12"));
map.put("20",new Integer("20"));
map.put(30,new Integer("30"));
if i am using treemap
TreeMap map1=new TreeMap(map);
System.out.println(map1);
answer is
1 ,10,11,12,2,20,3,30,4
but i am accepting the results
1,2,3,4,10,11,12,20,30.
what to do
with regardsshannu sarma[/b]This is usual behaviour of a Map. You cannot sort a Set or Map. You can sort a List only using Collections.sort().
If you want to use a Map which adds all elements according to the order you've added it, then use LinkedHashMap.
And if you want to capture the keys, use Map.values() which returns an ordered Collection (and after converting it to List, you can sort it).
Another approach is to create a wrapper object and put it in a List. Then you can use the java.util.Comparator to sort objects in a List. -
My while loop doesnt seem to work in a hash map, it works fine when I loop an array list.
It compiles but it doesnt seem to find any employees, should I use another loop?
{code
public Employee find(String id)
Employee foundEmployee = null;
int index = 0;
boolean found = false;
while(index < register.size() && !found){
Employee right = register.get(index);
String namn = right.getName();
if (namn.equals(id)){
foundEmployee = right;
found = true;
index++;
return foundEmployee;
what if you looped on the key set?
public Employee find(String id)
Employee foundEmployee = null;
Set<Integer> keySet = register.keySet();
for (Integer key : keySet)
Employee right = register.get(key);
if (right.getName().equals(id))
foundEmployee = right;
break;
return foundEmployee;
}
what if you looped on the key set?
public Employee find(String id)
Employee foundEmployee = null;
Set<Integer> keySet = register.keySet();
for (Integer key : keySet)
Employee right = register.get(key);
if (right.getName().equals(id))
foundEmployee = right;
break;
return foundEmployee;
}
SYSERR(root): hash map "Alias0"
Hi,
I am getting the following errors on Solaris 10, can anybody help me how to fix these errors?
SYSERR(root): hash map "Alias0": unsafe map file /etc/mail/aliases.db: World writable directory"
SYSERR(root): dbm map "Alias0": unsafe map file /etc/mail/aliases: No such file or directory"
Thanks in advance
Br
MJ Awan
those errors are telling you:
1. that you need to run /etc/mail/cf/sh/check-permissions. Also check that your / (root) directory perms are 755.
2. you need to create or restore your /etc/mail/aliases file. Hopefully you have an /etc/mail/aliases.db file?
How to create a huge interactive map?
Hello everybody
I've started learning Flash two weeks ago and I have the challenge of creating an interactive political map with about 4000 cities. Some cities will have more than 600 lines defining their limits which will make this project very demanding on processing.
People will be able to zoom in/out, select cities and see information about them.
As a starting point, I've begun working with 500 cities. I've imported a vectorial drawing of these cities and converted each one of them to symbols using flash javascript, resulting of course in 500 symbols. I don't know if it was a good way of starting this project but worked for me. Then my problems begun.
First I tried to use the mouse roll over and roll out events to change the (fill) color of cities but the city limits (stroke) changed also.
Second I want to add some properties to the cities such as city code, name, etc. but I wasn't able to do that using class inheritance. Would I have to create a different City class for every symbol I would like to extend? This approach looks like a lot of headache and redundant work.
Finally my question is should I start all over again and change my approach? If yes, how? If no, how can I solve those two problems?
Thanks
can't answer everything but I find this project very ambitious for someone with 2 weeks experience. I give you credit for trying.
as for the color changes, in each city symbol you need to have a separate "fill" symbol so that you can change the color of the fill and not the stroke.
also this link will help you understand the concept and confusion of target, currentTarget, mouse_over vs roll_over:
http://www.wastedpotential.com/?p=10
if each of your mc's is using a City.as class, that should work fine for giving each city the same properties. No need to create 500 different classes. I'm not an OOP expert but I know what you are trying is very possible and should be straight-forward.
Get Colin Moock's Essential ActionScript 3.0 and Shrupe's Learning ActionScript 3.0 for a crash course on implementing something like this.
Java.lang.ClassCastException while creating array descriptor
( This post was moved from SQL / PLSQL forum to here )
Hi everyone, i used to pass string array from java to plsql. I wrote a java source, then i load db with loadjava. And i wrote java spec. Then i run the function but i am getting this error :
java.lang.ClassCastException
at oracle.jdbc.driver.PhysicalConnection.putDescriptor(PhysicalConnection.java:4921)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:208)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:175)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:158)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:125)
at SplitterOracle3.tokens2(SplitterOracle3.java:29)
My Java Source is :
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import oracle.sql.*;
import oracle.jdbc.driver.OracleConnection;
import oracle.jdbc.driver.OracleDriver;
public class SplitterOracle3 {
public static oracle.sql.ARRAY tokens2(String str,String delim)
try
//Class.forName("oracle.jdbc.driver.OracleDriver");
//DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
//Connection conn = new OracleDriver().defaultConnection( );
OracleDriver ora = new OracleDriver();
OracleConnection conn = (OracleConnection) ora.defaultConnection();
//ArrayDescriptor arrayDesc = ArrayDescriptor.createDescriptor("MY_ARRAY", ((conn).getRealConnection());
//Connection conn = DriverManager.getConnection("jdbc:default:connection:");
//Connection conn = ((DelegatingConnection) getDataSource().getConnection()).getInnermostDelegate();
// get an initial context
//OracleConnection oracleConnection = (OracleConnection)WSJdbcUtil.getNativeConnection((WSJdbcConnection) wsConn);
ArrayDescriptor arraydesc =
ArrayDescriptor.createDescriptor ("ARR_VARCHAR_100", conn);
String strarr[] = new String[47];
strarr[0]="ahmet";
strarr[1]="mehmet";
int curIndex = 0;
int nextIndex = 0;
boolean nextIsLastToken = false;
int i=0;
while (true)
nextIndex = str.indexOf(delim, curIndex);
if (nextIsLastToken)
//return false;
break;
if (nextIndex == -1)
nextIsLastToken=true;
nextIndex = str.length();
strarr[i] = str.substring(curIndex, nextIndex);
curIndex = nextIndex + 1;
i++;
ARRAY dirArray = new ARRAY(arraydesc, conn, strarr);
return dirArray;*/
catch(Exception ex)
System.err.println(ex.getMessage());
ex.printStackTrace();
return null;
public static void main(String[] args)
String str="2000,2,123553168,1,10,64895,65535,27662,64860,64895,65535,27662,64860,0,,,,,,0,0,2491039806,,,,,,,,,0,0,1,,2491039106,,,,,,,,,,,,";
String strarr[] = new String[47];
long l1,l2;
int j=0;
l1 = System.currentTimeMillis();
for ( int i=0; i<20000000; i++)
strarr = tokens2(str,",");
l2 = System.currentTimeMillis();
System.out.println("Fark :"+ (l2-l1));
The line has "ArrayDescriptor.createDescriptor ("ARR_VARCHAR_100", conn);" causes this error.
java.lang.ClassCastException
at oracle.jdbc.driver.PhysicalConnection.putDescriptor(PhysicalConnection.java:4921)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:208)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:175)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:158)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:125)
at SplitterOracle3.tokens2(SplitterOracle3.java:29)
But i could not find the solution. Can you help me?
Thanks for responses.
Hi,
Did you try my suggestion from Re: java.lang.ClassCastException while create array descriptor
Try replacing
oracle.jdbc.driver.OracleConnectionwith
oracle.jdbc.OracleConnectionRegards
Peter
How to create an occupancy grid map
I am using a LIDAR sensor (URG-04LX) to map an environment for DaNI 1.0 in LabVIEW Robotics 2010 module. I want to create an occupancy grid map of the environment to use for path planning purposes. Can anyone provide me with any assistance. I have looked at the examples for path planning using the A* technique on an occupancy grid but I don't understand how to create the occupancy map.
... everyone above as told you how to create and LABVIEW occupancy map.... using an occupancy map.
The labview VI assumes you know exactly what the envrioment is like. Meaning you pretty much have some representation of the enviroment.
What you want to know is how do I generate and occupancy map using a laserscanner. For this you would need something called SLAM. Simultaneous localisation and Mapping. In order generate an occupancy map you need to continously localise your system so you can map laser measurements with refference to a fixed refferece frame, you then have to localise with respect to your map and repeat. This is non-trivial !
unfortuently there is no LabviewVi to do this for you, and there is not much working example code. So honestly if you want to do this, i would use a robotic development framework call ROS and using gmapping (which is a SLAM package). Alternatively if you inist on using labview you could create a dll of the gmapping (open source libary) and call it from labview, Our you could try to implement it from scratch yourself....
I just wish it was easier to use opensource libaries like pcl,opencv and integrate with textbased langauges using a labview system... it would make labview so much better, but labview robotics i feels is not really a good robotic application framework comapared to alternatives like ROS which have much bigger communities and much more modules of code you can use... escpecially for SLAM
https://decibel.ni.com/content/docs/DOC-22790 this is the best i have managed to find ( they do implement SLAM for this)
http://www.ros.org/wiki/gmapping
Create array varible in TestStand 4.0
Hi gurus,
I have a doubt that how can we create Array of string in TestStand 4.0 using C#.NET environment.
I used following method, but failed to create array:
objPropertyObj.SetValStringByOffset(10,PropertyOptions.PropOption_InsertIfMissing,"SRU"); // exception here....
The other following method creates array with empty size:
objPropertyObj.NewSubProperty("SUBSTITUTE.SRU", PropertyValueTypes.PropValType_String, true, "Arrayw",10 );
Please let me know how to set the length of the array at second method.
Thank you,
regards
RKK
You should post to the TS board.
Try to take over the world!
How can i create a more detailed map in aperture?
How can i create a more detaled map in Aperture- Book?
There are no templates for more detailed maps in Aperture.
You might consider to add more detailed maps as photos to the photo boxes in the book. I sometimes simply take a screenshot of the map in "Places" view to get a more detailed map with the pins marking the places.
How to store double variable in hash map
i need to store double variable using hash map, but i cant able to store it
my jsp coding contains
double et=24,j=5;
hm.put("stm",st);
hm.put("etm",et);
Generated servlet error
C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\exam\org\apache\jsp\availability_jsp.java:752:
put(java.lang.Object,java.lang.Object) in java.util.Map cannot be applied to (java.lang.String,double)
hm.put("stm",st);
^
how to overcome this problem
thank u in advance
double etme;
etme = hm.getDouble("etm");
i'm getting this error
C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\exam\org\apache\jsp\editdel_jsp.java:85: cannot resolve symbol
symbol : method getDouble (java.lang.String)
location: interface java.util.Map
etme = hm.getDouble("etm");
^
how to solve it
plz help me
How to create mass users and map them to existing hrms users
Hi,
Im running oracle ebusiness suite 12i . I want to create mass users , and map them to existing hrms users.
The users I want to create exist in an excel spreadsheet with the columns employee id, user name. They will all be granted the same responsibility. I want to map them to existing hrms users using the employee id key.
I have read about the package FND_USER_PKG.CREATEUSER and I can loop over it by using sql loader to create a temporary table, but I m lost on how to automatically map them to hrms users as part of the script.
Any help.
dula
Thanks a lot Omka,
I managed to create the users by running the script:
declare
Cursor C1 is
select d.product_code,b.responsibility_key from FND_USER_RESP_GROUPS_ALL a,fnd_responsibility b,fnd_user c,fnd_application d
where a.user_id = c.user_id
and a.responsibility_id = b.responsibility_id
and b.application_id = d.application_id
and c.user_name ='JOCHIENG';
Cursor employee is
SELECT EMPLOYEE_ID,EMPLOYEE_NAME from eldoret_final;
BEGIN
for e in employee loop
fnd_user_pkg.createuser
x_user_name => e.EMPLOYEE_NAME
*,x_owner => ''*
*,x_unencrypted_password => 'welcome123'*
*,x_start_date => SYSDATE - 10*
*,x_end_date => NULL*
*,x_description => 'CBK Employee'*
*,X_EMPLOYEE_ID => e.EMPLOYEE_ID*
fnd_user_pkg.addresp(upper (e.EMPLOYEE_NAME),'PER', 'CBK_EMPLOYEE_DIRECT_ACCESS','STANDARD', 'DESCRIPTION', sysdate, null);
end loop;
commit;
end;
I had first created the user JOCHIENG and assigned it the responsibility for Self service. So the script just assigns the responsibilities by copying from the one assgined to this user.
Everything seems ok. However, when trying to log in as the new user, the login error: Login failed. Please verify your login information or contact the system administrator.
is returned. But I can reset the password using the forms under Security > Define. Even with the correct password, the login doesn't go through.
Any idea?
dula
Maybe you are looking for
-
Ipod classic not recognized in itunes
Have a new 80 gb classic. Recognized in my computer and says 'connected' on ipod screen, but not showing up in itunes device menu. Have reset ipod multiple times and removed and downloaded new 7.5 version 3 times. Been on 3 hour long calls with tech
-
My LG Lucid keeps turning itself off
I haven't had any problems with it, until recently. I've had it about three or four months, and now it just randomly turns itself off. It just started doing this yesterday, and today it's happened six or seven times. I do use my phone a lot, I listen
-
How to Stop Auto assignment of Source of Supply in SC
Hi All; We are using SRM7 classic scenario. While creating a SC, the system automatically assigns a vendor in the source of supply if there is 1 contract or 1 inforecord.If there are multiple, the system will not assign but it will show them all so
-
Lightroom 5 publish services - order of published images
I have created several collections in which I have manually sorted the photos in a certain order. I am going to use them in a book (will be sending them to SmartBooks) and I don't want to reorder them once they are published to my hard drive. I have
-
IPhoto does not appear on desktop, only in Dashboard mode
Hey guys, Has anyone had this problem - the iPhoto window does not appear on the desktop, and can only be seen in Dashboard mode. Once that tiny window in the Dashboard mode is clicked, the program hides. I hope to hear from someone soon about this.