Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am newbie to Android and I am working in an Android project. I want to implement a data model, using that model I want to perform the arithmetic operations using the Hash Map.

But I don't know how to implement it. And also I want to print the value in Text View. The project is like an Calculator.

ModelActivity

Create the getter and setter I don't know how to implement this

MainActivity

Using that Model I have to perform the operation like getting and setting the value using the Hash map.

This is my model class

public class Model {

    public Map<String, String> getSmap(String string, String str) {
        return Smap;
    }

    public Map<Integer, Integer> getImap() {
        return Imap;
    }

    public Map<String, Integer> getSImap() {
        return SImap;
    }

    public Map<Integer, String> getISmap(String jeeva, String s) {
        return ISmap;
    }

    private Map<String, String> Smap = new HashMap<>();
    private Map<Integer, Integer> Imap = new HashMap();

    private Map<String, Integer> SImap = new HashMap<>();
    private Map<Integer, String> ISmap = new HashMap<>();

    public Map<Integer, String> getISmap(String jeeva) {

        return ISmap;
    }
}

Using that model I want to perform the operations like add sub.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
266 views
Welcome To Ask or Share your Answers For Others

1 Answer

For my understanding you want to know how to populate HashMaps. So first of all you should read this documentation: https://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html

Code:

Map<String, String> map = new HashMap<>();

// Add things to the map
map.put("key","value");

// Get values from map
String value = map.get("key");

In very generic terms with this you can start doing stuff :) but you should absolutely read the documentation and have a deep understanding regarding how a Map works and then decide which type of Map you need to fulfil your requirements.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...