Map (Hashmap) to Array

Hello Java Friends,
Please, I have a map (Mappings = new HashMap<String, Integer>) which contains both String and Integer elements. I wanted to store the string elements of the Map in a String Array and Integer elements in Integer Array but end up with error messages. How can I implement it?
See part of my code below:
public class Tryit{
private  Map<String, Integer> Mappings;
String[]StringElem;
int [] IntegerElem;
public Tryit(){
Mappings  = new HashMap<String, Integer>()
StringElem = new String [100];
IntegerElem = new int [100];
for (String index : Mappings.KeySet()){
StringElem = index;
for (int i : Mappings.values(){
IntegerElem = i;
}

Hello friends,
The idea you gave me worked but still I am having a small problem: I have two classes, class A and B. In Class A, I implemented a set and get method which I will use in Class B to retrieve the keys and Values. But when I call the get method in Class B, I always get null. The arrays in both classes are all declared globally.
Get and Set Method in Class A :
public void setKeyValues() {
          int i = 0;
          for(Map.Entry<String, Integer> e: map.entrySet()) {
               ElementName= e.getKey();
          i++;
public String []getKeyValues(){
     return ElementName;
Call the Get Method in Class B
import package X.A
public class B{
private String [] names;
public B(){
A bix = new A();
int length = bix.getKeyValues().length;
names = new String[length];
System.out.printf ("%d", gettingKeys(bix.getKeyValues());
public String[] gettingKeys(String []naming) {
          names = new int[bix.getKeyValues().length];
          int size = naming.length;
          for (int p = 0; p < size; p++) {
               names[p]=naming[p];
               p++;
          return names;
     }Please where is the problem ?? I am unable to read and print the map values and keys from another friend class.
Jona_T

Similar Messages

  • JDO : how to map a byte array field correctly

    Could someone please provide an example on how to correctly map a byte array field in a PCClass.
    The field should be mapped to a BLOB field in my Dictionary project.
    The checker keeps throwing errors during the enhancement process. Tried all sorts of combinations of xml in my jdo and map file (using the dtd) but I still haven't found the solution. The compilation works fine though, it is only the checker that complains.

    You're already in a PDF open in Acrobat (not the free Adobe Reader) and you've made a new PDF? Which you want to save to disk and reopen?

  • Looking up values from Map/HashMap  when Objects are used as keys

    I'm trying to understand why Map/HashMap don't test for equals() when looking up a key ( which is an Object that overrides equals() and hashCode()) in the Map.
    I've written this code, based on some code from the SCJP book, but it is not exactly the same, this code talks about a different issue not addressed in the book.
    I've added my questions inside the comments below, I think that is the best way I can ask it.
    import java.util.*;
    class Bird{
         public String name;
         public Bird(String name){
              this.name = name;
         //Override equals()
         public boolean equals(Object o){
              if(((Bird)o).name.equals(this.name)){
                   return true;
              }else{
                   return false;
            //Override hashCode
         public int hashCode(){
              return name.length();
    class TestMapLookup{
         static public void main(String[] args){
              Map<Object, Object> hashMap = new HashMap<Object, Object>();
              Bird b = new Bird("crow");
              hashMap.put(b, "somevalue");
              //according to the book, the map object calls the key's (Bird object's)
              //hashCode() first and then equals()
              //to find this key in the map
              System.out.println(hashMap.get(b));
              //Using the b reference to lookup value
              //ouputs - somevalue
              System.out.println(hashMap.get(new Bird("crow")));
              //Using a new Bird object to lookup value
              //outputs - somevalue
              //because Bird overrides equals and hashCode
              //otherwise we'd get null
              //Now change the name of the bird in the b reference
              b.name = "sparrow";
              //Notice that the crow's hashCode is 4
              //sparrow's hashCode is 7 , in the above implementation of hashCode
              System.out.println(hashMap.get(b));
              //Again using b reference to lookup value
              //ouputs - null
              //because the hashCode of b.name does not match
              //the hashCode of any of the keys stored in the map
              System.out.println(hashMap.get(new Bird("crow")));
              //This also outputs null
              //for the same reason that there's no key in the map
              //with a hashcode of 7
              //This is where it becomes strange......................
              //Change the name of the bird in the b reference
              //so that the new name has the same hashCode, as the key in the map
              b.name = "dove";
              System.out.println(hashMap.get(b));
              //In the above - the hashCode matches
              //but equals() fails
              //even though equals() fails, the key is still located and the value is output
              //output is "somevalue"
              //same here:
              b.name = "1234";
              System.out.println(hashMap.get(b));
              //output is "somevalue" instead of null
              b.name = "abcd";
              System.out.println(hashMap.get(b));
              //output is "somevalue" instead of null
              //why does it output "somevalue" instead of null , even though when the map
              //looks up the key , equals() returns false?     
              System.out.println(hashMap.get(new Bird("crow")));
              //In this case ( new Bird reference ) it prints null
    }I'm aware of best practices in coding and coding conventions but haven't used them here, because this is in preparation for SCJP - which tests on a lot of different things.
    I appreciate any info.

    It is correct that b is referring to the same object that the map's key is pointing to, but why does the following
    print null , instead of "somevalue"?
    at these lines in the code above.
    b.name = "sparrow";
    System.out.println(hashMap.get(b));Because the hashCode used when you stored b was 4, and now it's 7. You should read the Wikipedia article on Hashtable, but a simplistic explanation is that a HashMap has a bunch of "buckets," say 10, each indexed with a number 0-9. To decide which bucket to put a new key-value pair in, you take the hashcode (say 2112) and take the remainder of hashcode/number of buckets (in this case, 2112%10=2). So when you store the key-value, it gets "put" in this bucket.
    When you change the hashcode of b by changing its name attribute, it doesn't change the fact that the pair is in that bucket. But, it now looks in the wrong bucket and so can't find the pair.
    A hashtable gets its good efficiency by not having to look through all values to find the pair. It can jump directly to the correct bucket, which takes constant time instead of being dependent on the number of items in the collection.
    endasil wrote:
    You should never, ever change an object being used as a key in a map.I guess this is a best practice, I just wanted to try changing the key object to test a few things for SCJP, which does not test on coding best practices but tests on how the code behaves.Yep, and what you should take away is that this is WHY it's bad to change the key :).

  • HashMaps and Arrays

    I am extracting data from MYSQL in a result set. The values are then stored in HashMap. The total count of rows would be around 650 - 700 approx. I get a Array out of Bound exception.
    (Note: I have a HashMap array- HashMap hm[] = new HashMap[800]; )
    Any one to comment on this. If you need any more information.. let me know...
    -Krish

    PMJain wrote:
    Why do you allocate a HashMap[]?
    you would need a single instance of HashMap to be populated with some key/value pairs
    where key might be your primary key and the value could be the object with the data from a single record.My guess is that Cubby was turning each result set row into a Map that mapped the column name to the row's value. Meh.

  • Chosing from Vectors, HashMaps or Arrays

    Hi All,
    I have to decide on which of these to use for my problem. I want a Collection that holds values like
    [Name, year of Birth]
    ["Tom", 1952]
    ["Dick", 1972]
    ["Harry", 1992]
    .where the first element is a String type and its related element is an integer ...
    the age old solution looks like using a 2-D array ... but in my case the list has to expand vertically and it could be possible that I have more data values laterally as well like "Age" field added up
    ["Tom",  1952, 53, ...... ]
    .I am not able to make up my mind as to chosing between Vectors or Hashmaps or Lists for this situation .... I want to avoid usng a n-D array and instead use some of the features offered by Java ...
    since I am relatively new to Java ... please explain why one should use a vector or a hashmap for this

    1. Definitely not Vector, unless you need synchronization. Use ArrayList instead.
    If your key is always the name, and the person may have many attributes, create a person class.
    class Person
       String name;
       int YearOfBirth;
       String phoneNumber;
       //whatever 
    }Put them in a HashMap with keys of name, and values of Person. Then if you want to add more attributes to Person, it is easy--your HashMap data structure won't change.
    Map map = new HashMap();
    map.put("Tom", new Person("Tom", 1952, "555-555-5555"));
    //or, maybe better, so name isn't duplicated incorrectly:
    Person person = new Person("Tom", 1952, "555-555-5555"));
    map.put(person.getName(), person);

  • Hashmap and array list problems

    This is an assignment I have to do and I do NOT expect anyone to do the coding for me. I am just looking for some direction as I have no clue where to go from here. Any guidance would be very welcomed.
    We were given code that used just an Array lisThis is an assignment I have to do and I do NOT expect anyone to do the coding for me. I am just looking for some direction as I have no clue where to go next. Any guidance would be very welcomed.
    We were given code and told to "Modify the MailServer so that it uses a HashMap to store MailItems. The keys to the HashMap should be the names of the recipients, and each value should be an ArrayList containing all the MailItems stored for that recipient. " Originally it was just an ArrayList named messages. There is also a MailClient and MailItem class.
    I think I can post the messages using the HashMap now, but can't test it. I get a compiler error saying else without if even though I have an if statement. Even if I can compile, I need to make sure I am on the right track with the getNextMailItem method. It is the one I am stuck on and if I can get it to work, I can probably modify the other methods.
    I would really appreciate feedback on that one method.
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    public class MailServer
         // Storage for the arbitrary number of messages to be stored
         // on the server.
         private HashMap messages;
         private ArrayList list;
         private MailItem item;
          * Construct a mail server.
         public MailServer()
             messages = new HashMap();
             list = new ArrayList();
          * Return the next message for who. Return null if there
          * are none.
          * @param who The user requesting their next message.
         public MailItem getNextMailItem(String who)
              Iterator it = list.iterator();
              while(it.hasNext())
                MailItem item = (MailItem)it.next();
                if(messages.containsKey(who));
                    return item;
               else
                   return null;
          * Add the given message to the message list.
          * @param item The mail item to be stored on the server.
         public void post(String name, MailItem item)
             if(messages.containsKey(name))
                    list = (ArrayList) messages.get(name);
                    else {
                        list = new ArrayList();
                        list.add(item);
                        messages.put(name, list);
    }[                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    The way I understand this is that MailItems are stored in per user ArrayLists, and that the ArrayLists are stored in the HashMap, and use the username as a key,
    HashMap messages = new HashMap();
    //ArrayList userMailItems = new ArrayList(); this should not be declared here, only the messages mapso given a User name, you need to get the list of mail items for that user out of the hashMap, and then return the next MailItem from the list. So given that, you don't even need to Iterate over the list:
    public MailItem getNextMailItem(String who)
    ArrayList list = (ArrayList)messages.get(who);
    if(list == null || list.size() == 0)
    return null;
    //now we get the next item from the list, we can call remove, since it returns the object we are removing.
    MailItem item = (MailItem)list.remove(0);
    return item;
    }

  • UML Modelling 1:n shouldn't map to an array

    Hi,
    I'd like to use the UML diagrammer to build up a class with a simple master-detail relation between objects. The code-generator implements this automatically to an array.
    But I'd like to use a more sophisticated class like a vector or map?
    Any idea how to get the uml diagrammer to do this?
    Regards,
    Ingo

    Hi,
    Sadly you can't set a collection type of the UML elements so when they are converted to Java they become different collection types.
    You can our course set the collection types when you have transforms to java using the association dialog. You will find that subsequent transforms will preserve the collection type on the java side though.
    Sorry we can't be more helpfull,
    Gerard

  • Creating colour image map from an array of integers

    not really that relvant to swing, or in fact java even but i wasnt sure where to ask it so:
    i have an array of integers that represents information about each pixel in an image. i.e. for every pixel there is an integer value.
    at the moment i create another image from a quantised version of these integer values, which gives me a greyscale image, where black is low intensity info and white is high.
    however what i want to do is create a colour image like you see, for example, on weather forecasts. where low intensity info is blue, then purple, then red, orange, yellow and then white being the highest.
    i need some kind of algorithm that does this. does anybody have some code that does this already?
    thanks
    kevin

    sorry for not replying sooner sniper. thanks for your help but i have solved the problem:
    thanks to my mate marc for the code.
    import java.awt.Color;
    /** Class to assist in assigning color to a mathematical value.
    *  Data values must be normalized.
    *  @author Marc Ramsdale
    *  Written 20th August 2003
    public class ColorScale {
         /** Receives a normalized value (between 0.0 - 1.0)
          *  The constructor then creates a colour according
          *  to the selected colour scale.
          *  If value is outside range 0.0 - 1.0 colour is java.awt.Color.BLACK
          *  @param double value - (between 0.0 - 1.0)
         /** Maps the normalized value to a color
          *      BLUE      *
          * GREEN    *      *
          * RED           *
         public static Color generateColour(double value) {
          double red = 0.0;
          double green = 0.0;
          double blue = 0.0;
          Color color;
          int gradient = 4;
          int offset1 = 2;
          int offset2 = 4;
              if((value >= 0.0) && (value < 0.25)) {
                   red = 0.0;
                   green = value * gradient;
                   blue = 1.0;               
              else if((value >= 0.25) && (value < 0.5)) {
                   red = 0.0;
                   green = 1.0;
                   blue = -(value * gradient) + offset1;
              else if((value >= 0.5) && (value < 0.75)) {
                   red = (value * gradient) - offset1;
                   green = 1.0;
                   blue = 0.0;
              else if((value >= 0.75) && (value <= 1.0)) {
                   red = 1.0;
                   green = -(value * gradient) + offset2;
                   blue = 0.0;
              return new Color((float)(red), (float)(green), (float)(blue));

  • Can we support Map/HashMap in the webservice as one of internal parameters?

    Hi all,
    I have written a simple webservice. Which just prints the content of the input.
    public class ServiceClass {
         public MyVO printContents(MyVO vo) {
              System.out.println(vo.getName());
              System.out.println(vo.getParams());
              return vo;
    public class MyVO {
         private String name;
         private HashMap<String, Serializable> params;
         public String getName() {
              return name;
         public void setName(String name) {
              this.name = name;
         public HashMap<String, Serializable> getParams() {
              return params;
         public void setParams(HashMap<String, Serializable> params) {
              this.params = params;
    I am using Eclipse Java EE IDE for Web Developers.(Version: Helios Service Release 1) for generating stubs like this :
    New wizard , webservice, Selecting the server runtime (tomcat 6) and webruntime as Axis2. And clicking finish.
    It generates the project with name TestClient. And inside that 2 classes : ServiceClassCallbackHandler and ServiceClassStub.
    Once WebService is generated its also opening one JSP (WebService explorer) . In that I can see the WebService and clicking on basicwebservice it shows UI where I can input my data.
    But its not showing if I can add key/value for map.
    I am not sure how to test this?
    More importantly can I test my webservice that it prints the passed data?
    How to pass the test data to this webservice?
    Or how to pass MyVO object to the webservice?
    Thanks in advance.

    Hi Ronni
    This forum is not the right place where you can find your answer easily. To catch more answers you can try posting your question to one of the following forums:
    1. <a href="https://www.sdn.sap.com/sdn/collaboration.sdn?node=linkFnode1-1&contenttype=url&content=https%3A%2F%2Fforums.sdn.sap.com%2Fforum.jspa%3FforumID%3D41">EP Content Development Forum</a>
    2. <a href="https://www.sdn.sap.com/sdn/collaboration.sdn?node=linkFnode2-4&contenttype=url&content=https%3A%2F%2Fforums.sdn.sap.com%2Fforum.jspa%3FforumID%3D59">Java Programming Forum</a>
    *--Serdar
    Moved the post to Java Programming.
    Thanks for the post, Mark. 
    Message was edited by: Mark Finnern

  • How to use XSLT for mapping feild names one by one to array element

    I have a XSLT case to map all the attributes feild name(not value) which has no child to the target, which is array loop.
    I give an sample below.
    source:
    <Items xmlns="http://www.example.org/sample">
    <SourceSystem>SourceSystem2573</SourceSystem>
    <TimeStamp>2010-01-17T20:54:08.234</TimeStamp>
    <Item>
    <ID>2574</ID>
    <Type>2575</Type>
    <Name>2576</Name>
    </Item>
    </Items>
    source XSD like:
         <element name="Items" type="tns:ItemsType"></element>
         <complexType name="ItemsType">
              <sequence>
                   <element name="SourceSystem" type="string" maxOccurs="1"
                        minOccurs="1">
                   </element>
                   <element name="TimeStamp" type="dateTime" maxOccurs="1"
                        minOccurs="1">
                   </element>
                   <element name="Item" type="tns:ItemType"
                        maxOccurs="unbounded" minOccurs="1">
                   </element>
    </sequence>
         </complexType>
    <complexType name="ItemType">
              <sequence>
                   <element name="ID" type="string" maxOccurs="1"
                        minOccurs="1">
                   </element>
                   <element name="Type" type="string" maxOccurs="1"
                        minOccurs="1">
                   </element>
    <element name="Name" type="string" maxOccurs="1"
                        minOccurs="1">
                   </element>
    </sequence>
         </complexType>
    target need to be like:
    <ns1:AttributesCollection>
    <ns1:Attributes>
    <ns1:fieldname>SourceSystem</ns1:fieldname>
    </ns1:Attributes>
    <ns1:Attributes>
    <ns1:fieldname>TimeStamp</ns1:fieldname>
    </ns1:Attributes>
    <ns1:Attributes>
    <ns1:fieldname>ID</ns1:fieldname>
    </ns1:Attributes>
    <ns1:Attributes>
    <ns1:fieldname>Type</ns1:fieldname>
    </ns1:Attributes>
    <ns1:Attributes>
    <ns1:fieldname>Name</ns1:fieldname>
    </ns1:Attributes>
    </ns1:AttributesCollection>
    target XSD:
    <xs:element name="AttributesCollection" type="AttributesCollection"/>
    <xs:complexType name="AttributesCollection">
    <xs:sequence>
    <xs:element name="Attributes" type="Attributes" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="Attributes">
    <xs:sequence>
    <xs:element name="fieldname" minOccurs="0">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:maxLength value="100"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    I know we can use local-name() to get the tag/field name,
    but I have not idea how to get these leaf field names one by one and then mapping to every array elements.
    I tried whole day but no successful
    Does anyone have some idea?
    Thanks very much!
    Keith
    Edited by: user1065212 on 17-Jan-2010 22:50
    Edited by: user1065212 on 17-Jan-2010 22:53
    Edited by: user1065212 on 17-Jan-2010 22:59

    can you paste source xsd and the correct xml output, the current one isn't really valid
    <ID>2574</TotalNumOfItems>

  • Mapping Java Arrays

    I was given an object model generated by an apache product, Axis. The generated java files use the Java Array in the following fashion:
    Class Zoo {
    private ArrayOfAnimals animals;
    // … public get/set methods cut
    Class ArrayOfAnimals {
    private Animal animals[];
    // … public get/set methods cut
    Class Animal {
    private String name;
    // … public get/set methods cut
    I was tasked with mapping the one-to-many relationship between zoo and an array of animals using the Animal array. I can’t find a mapping in TopLink to do this type of association. I am NOT allowed to modify the generated source code. I may be able to extend the generated classes, and perhaps provide a different superclass.
    I am allowed to create the relational model for these domain classes. Can anyone help with this type of mapping?
    Thanks

    TopLink does not directly support arrays as the mapping type for a collection, only collection types that support the Collection and Map interfaces.
    In general it seems odd to use an array instead of a Java collection which would be much more efficient (in terms of adding and removing) and much more functional. I would definitely suggest changing the generated code, or the way the code is generated if at all possible.
    The easiest way to map the array in TopLink would be the use get/set methods for the 1-m mapping on the Zoo class that converted the array to/from a Collection.
    i.e. something like,
    public List getAnimalsList() {
    return new Arrays.asList(animals.animals);
    public void setAnimalsList(List list) {
    animals.animals = (Animal[]) list.toArray();
    In general TopLink uses its ContainerPolicy class to handle collections. It may also be possible (but advanced) to write a custom container policy for your 1-m mapping that handles arrays.

  • Help with HashMap!!!

    Hi all,
    My program reads the data from the external file called: "long.txt" which consists of a million records...
    The file is loaded into a list called: "HashMap list" and also store the keys into a separate array. Search is done in HashMap for all the key in the array or also known as an exhaustive search.
    I have the files: "long.txt", "HashMapTestnew.java" and "MyData.java" in the same directory called: "tmp"...
    Everything looks okay but when I try to compile this, I get the following error...
    HashMapTestnew.java:38: cannot resolve symbol
    symbol : class MyData
    location: class MyData.HashMapTestnew
    MyData md = new MyData( sKey, Integer.parseInt(sVal) );
    ^
    HashMapTestnew.java:38: cannot resolve symbol
    symbol : class MyData
    location: class MyData.HashMapTestnew
    MyData md = new MyData( sKey, Integer.parseInt(sVal) );
    ^
    HashMapTestnew.java:55: cannot resolve symbol
    symbol : class MyData
    location: class MyData.HashMapTestnew
    MyData md;
    ^
    HashMapTestnew.java:66: cannot resolve symbol
    symbol : class MyData
    location: class MyData.HashMapTestnew
    md = (MyData) me.getValue();
    ^
    4 errors
    Tool completed with exit code 1
    import java.util.*;
    import java.io.*;
    public class HashMapTestnew
    public static HashMap getMapList()
         String MyData;
         Int sKey;
    String strLine;
    HashMap hm = new HashMap();
    try
    BufferedReader fBR = new BufferedReader( new FileReader("long.txt") );
    while ( fBR.ready() )
    strLine = fBR.readLine();
    if (strLine != null)
    StringTokenizer st = new StringTokenizer(strLine, "\t");
    String sKey = st.nextToken();
    String sVal = st.nextToken();
    MyData md = new MyData( sKey, Integer.parseInt(sVal) );
    hm.put(sKey, md);
    fBR.close();
    catch (IOException ioe)
    System.out.println("I/O Trouble ...");
    return hm;
    public static void showMapList(HashMap hashMap, int n)
    String strVal;
    String strNdx;
    MyData md;
    System.out.println("\nHashMap List (first 10 records):");
    Map.Entry me;
    Set shm = hashMap.entrySet();
    Iterator j = shm.iterator();
    int i = 0;
    while (j.hasNext() && (i++)< n)
    me = (Map.Entry) j.next();
    strVal = (String) me.getKey();
    md = (MyData) me.getValue();
    System.out.println(i + ": " + md.getVal() + "\t" + md.getNdx() );
    public static String[] getKeys(HashMap hashMap)
    String[] key = new String[hashMap.size()];
    Map.Entry me;
    Set shm = hashMap.entrySet();
    Iterator j = shm.iterator();
    int i = 0;
    while (j.hasNext())
    me = (Map.Entry) j.next();
    key[i] = (String) me.getKey();
    i++;
    return key;
    public static void searchMapList(HashMap hashMap, String[] key)
    int i,n=0;
    System.out.println("Search Started:");
    long tim1 = System.currentTimeMillis();
    for (i=0; i<key.length; i++)
    if (hashMap.containsKey(key))
    n++;
    long tim2 = System.currentTimeMillis();
    System.out.println("Search Ended After " + (tim2-tim1) + " miliseconds.");
    System.out.println("Searched for " + key.length + " keys.");
    System.out.println("Found " + n + " keys.");
    public static void main(String[] arg)
    HashMap hashMap = getMapList(); // Create the hash map list
    showMapList(hashMap, 10); // Display part of the hash map list
    String[] searchKey = getKeys(hashMap); // an array of all search keys
    searchMapList(hashMap, searchKey); // Search for all existing keys in the list
    Can anybody help me with this?
    I'm new to Java... What does the error message: "cannot resolve symbol
    symbol : class MyData" mean???
    P.S. When I compiled the file "MyData.java", it compiles without any error...
    Thanks,
    Lilian

    I moved the 3 files ("MyData.java", "long txt" and "HashMapTest.java") to a directory called "MyData" as well as added the code: "package MyData;"
    before the codes:
    import java.util.*;
    import java.io.*;
    just to see if it would make any difference but I still got the following error messages:
    C:\WINDOWS\DESKTOP\MyData\HashMapTest.java:38: cannot resolve symbol
    symbol : class MyData
    location: class MyData.HashMapTest
    MyData md = new MyData( sKey, Integer.parseInt(sVal) );
    ^
    C:\WINDOWS\DESKTOP\MyData\HashMapTest.java:38: cannot resolve symbol
    symbol : class MyData
    location: class MyData.HashMapTest
    MyData md = new MyData( sKey, Integer.parseInt(sVal) );
    ^
    C:\WINDOWS\DESKTOP\MyData\HashMapTest.java:55: cannot resolve symbol
    symbol : class MyData
    location: class MyData.HashMapTest
    MyData md;
    ^
    C:\WINDOWS\DESKTOP\MyData\HashMapTest.java:66: cannot resolve symbol
    symbol : class MyData
    location: class MyData.HashMapTest
    md = (MyData) me.getValue();
    ^
    4 errors
    Tool completed with exit code 1
    By the way, I'm compiling the java program using a Textpad editor and selecting Tools -->> Compile Java...
    Let me know if you have any questions...
    Thanks,
    Lilian
    location: class MyData.HashMapTestnewThis says that you have declared your HashMapTestnew
    class to be in package MyData.
    I have the files: "long.txt", "HashMapTestnew.java"and "MyData.java" in the same directory called:
    "tmp"...
    If you want HashMapTestnew to be in package MyData,
    then it should have been in a directory called MyData.
    But having a class with the same name as a package is
    very confusing, so I don't think you should do that.
    In fact, since you are new to Java I don't think you
    u should use packages at all until you can compile
    non-packaged classes correctly.
    I'm surprised I don't see the line "package MyData" at
    the top of the code you posted. But then I'm not
    surprised, because since your class isn't in the right
    directory for that package, you should have got
    different error messages. What exactly did you type
    at the command line to compile the class?

  • How to loop through an associative array

    Guys,
    How to loop through an associative array. where the key is string but the value is an object
    -Thanks

    It depends if you are using a Java HashMap or a BPM Associative array. You'd use the "keySet" if for the former and the "keys" if it's the latter.
    I know you want an object for the array, but Any[String] is used here just so you can see something coming back in the display statements shown below. Remove the input and display statements - they're just in there so you can see something working.
    Here's how to go through a Hashmap's array using a loop:
    map as Java.Util.HashMap
    map.put(1, "One")
    map.put(2, "Two")
    map.put(3, "Three")
    map.put(4, "Four")
    map.put(5, "Five")
    display map.keySet
    for each item in keySet(map) do
         display item
         display get(map, arg1 : item)
    endHere's how to go through an associative array using a loop:
    hashMap as Any[String]
    hashMap = ["One": 1,"Two":2]
    for each item in hashMap.keys do
         display item
         display "Item in the array is: " + hashMap[item]
    endDan

  • Array Of Primitive Type (kodo3.4)

    Hello,
    I want to map an array of primitive type (double[] or double[][] or...) to
    a blob, so I specified the mapping this way:
    <extension vendor-name="kodo" key="jdbc-field-map-name" value="blob">
    <extension vendor-name="kodo" key="column" value="DATA"/>
    </extension>
    As I use MySQL and not to have an exception, I have added:
    kodo.jdbc.DBDictionary: DriverDeserializesBlobs=false
    But when I tried to refresh using kodo.jdbc.meta.MappingTool, I get:
    [refresh] Exception in thread "main" kodo.util.FatalInternalException:
    Cannot map "fr.ifp.reservoir.model.business.geostat.Lithotype.facies".
    Check the class and make sure you are using only supported types.
    [refresh] at
    kodo.jdbc.meta.DynamicMappingProvider.createFieldMapping(DynamicMappingProvider.java:336)
    [refresh] at
    kodo.jdbc.meta.DynamicMappingProvider.getFieldMapping(DynamicMappingProvider.java:118)
    [refresh] at
    kodo.jdbc.meta.MappingRepository.getFieldMapping(MappingRepository.java:470)
    [refresh] at
    kodo.jdbc.meta.AbstractClassMapping.getFieldMapping(AbstractClassMapping.java:993)
    [refresh] at
    kodo.jdbc.meta.AbstractClassMapping.getFieldMapping(AbstractClassMapping.java:973)
    [refresh] at
    kodo.jdbc.meta.AbstractClassMapping.getMappings(AbstractClassMapping.java:939)
    [refresh] at
    kodo.jdbc.meta.AbstractClassMapping.getDeclaredFieldMappings(AbstractClassMapping.java:659)
    [refresh] at
    kodo.jdbc.meta.AbstractClassMapping.resolve(AbstractClassMapping.java:801)
    [refresh] at
    kodo.jdbc.meta.BaseClassMapping.resolve(BaseClassMapping.java:341)
    [refresh] at
    kodo.jdbc.meta.MappingRepository.resolve(MappingRepository.java:431)
    [refresh] at
    kodo.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:349)
    [refresh] at
    kodo.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:177)
    [refresh] at kodo.jdbc.meta.MappingTool.refresh(MappingTool.java:591)
    [refresh] at kodo.jdbc.meta.MappingTool.run(MappingTool.java:941)
    [refresh] at kodo.jdbc.meta.MappingTool.run(MappingTool.java:879)
    [refresh] at kodo.jdbc.meta.MappingTool.main(MappingTool.java:802)
    Thanks for your help.
    nicolas

    Hi,
    No more succes with persistence-modifier="persistent"...
    My class:
    public class ArrayWrapper {
    private String name;
    private double[] array;
    public ArrayWrapper(String name, double[] array) {
    this.name = name;
    this.array = array;
    public double[] getValues() {
    return array;
    public String getName() {
    return name;
    My metadata file:
    <jdo>
    <package name="model">
    <class name="ArrayWrapper">
    <field name="array" persistence-modifier="persistent">
    <extension vendor-name="kodo" key="jdbc-field-map-name" value="blob">
    <extension vendor-name="kodo" key="column" value="DATA"/>
    </extension>
    </field>
    </class>
    </package>
    </jdo>
    My StackTrace:
    refresh-mapping:
    [java] Exception in thread "main" kodo.util.FatalInternalException:
    Cannot map "model.ArrayWrapper.array". Check the class and make sure you
    are using only supported types.
    [java] at
    kodo.jdbc.meta.DynamicMappingProvider.createFieldMapping(DynamicMappingProvider.java:336)
    [java] at
    kodo.jdbc.meta.DynamicMappingProvider.getFieldMapping(DynamicMappingProvider.java:118)
    [java] at
    kodo.jdbc.meta.MappingRepository.getFieldMapping(MappingRepository.java:470)
    [java] at
    kodo.jdbc.meta.AbstractClassMapping.getFieldMapping(AbstractClassMapping.java:993)
    [java] at
    kodo.jdbc.meta.AbstractClassMapping.getFieldMapping(AbstractClassMapping.java:973)
    [java] at
    kodo.jdbc.meta.AbstractClassMapping.getMappings(AbstractClassMapping.java:939)
    [java] at
    kodo.jdbc.meta.AbstractClassMapping.getDeclaredFieldMappings(AbstractClassMapping.java:659)
    [java] at
    kodo.jdbc.meta.AbstractClassMapping.resolve(AbstractClassMapping.java:801)
    [java] at
    kodo.jdbc.meta.BaseClassMapping.resolve(BaseClassMapping.java:341)
    [java] at
    kodo.jdbc.meta.MappingRepository.resolve(MappingRepository.java:431)
    [java] at
    kodo.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:349)
    [java] at
    kodo.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:177)
    [java] at kodo.jdbc.meta.MappingTool.refresh(MappingTool.java:591)
    [java] at kodo.jdbc.meta.MappingTool.run(MappingTool.java:941)
    [java] at kodo.jdbc.meta.MappingTool.run(MappingTool.java:879)
    [java] at kodo.jdbc.meta.MappingTool.main(MappingTool.java:802)

  • Converting bytes to character array problem

    I am trying to convert a byte array into a character array, however no matter which Character Set i choose i am always getting the '?' character for some of the bytes which means that it was unable to convert the byte to a character.
    What i want is very simple. i.e. map the byte array to its Extended ASCII format which actually is no change in the bit represtation of the actual byte. But i cannot seem to do this in java.
    Does anyone have any idea how to get around this problem?

    Thanks for responding.
    I have however arrived at a solution. A little un-elegant but it seems to do the job.
    I am converting each byte into char manually by this algorithm:
              for (int i=0;i<compressedDataLength;i++)
                   if (((int) output)<0)
                        k=(127-((int) output[i]));
                        outputChr[i]=((char) k);
                   else
                        k=((int) output[i]);
                        outputChr[i]=((char) k);
                   System.out.println(k);
    where output is the byte array and outputChr is the character array

Maybe you are looking for

  • Letterboxed FCP output

    HELP!!!! I am a DP who shot a feature film last year. My editing background in NLE is pure AVID. The director edited the film on Final Cut Pro 5 -- we shot with a Canon XL2 in 24p (3:2:2:3) and native 16X9. Now that the film is done, so far, all the

  • Dual case fans and cd line in

    I have a 648Max-L and would like to hook up two case fans (my AMS CF-2029 clear case has two fan brackets in rear and one 80/120mm in front). In reading the manual and examining the board there is only one pin header for the case fan (sysfa)... so ho

  • Speeds slowed down to below estimated level

    Had Bt infinty installed before christmas 2011. Acheived the max of 38mbps and was happy Now however, My speeds have dropped to around 20mbps, confirmed by both speedtest.net and http://speedtester.bt.com/ I have found the very un-helpful call centre

  • Cisco Device Phone - MTP Required

    Hi, I have some calls, that route to the Firewall and make the asymmetric route (one side Jabber got the video & audio; one side is no video & audio) After I set the "MTP requested" on Jabber softphones, that can get the audio both sides I just want

  • Pdf books on iphone

    how can i put pdf books on iphone? i have the "ibooks" app. the books are in itunes in the books folder. i told itunes to sync, it showed it was but the books dont show up in the app.... did i do something wrong? what else do i need to do? thanks