本文介绍了如何在DataModel中使用HashMap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android的新手,我在Android项目中工作。我想实现一个数据模型,使用该模型我想使用哈希映射执行算术运算。



但我不知道如何实现它。而且我想在文本视图中打印该值。该项目就像一个计算器。



ModelActivity



创建getter和setter我不知道如何实现这个



MainActivity



使用该模型我必须执行操作,例如使用哈希映射。



这是我的模型类

  public class Model {

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

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

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

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

私人地图< String,String> Smap = new HashMap<>();
私人地图<整数,整数> Imap = new HashMap();

私人地图< String,Integer> SImap = new HashMap<>();
私人地图<整数,字符串> ISmap = new HashMap<>();

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

return ISmap;




$ b $ p
$ b

使用这个模型我想执行像add sub。

解决方案

为了我的理解,您想知道如何填充HashMaps。所以首先你应该阅读这个文档:



代码:

 地图< String,String> map = new HashMap<>(); 

//将东西添加到地图
map.put(key,value);

//从地图
获取值字符串值= map.get(key);

在这个非常通用的术语中,您可以开始做些事情:)但是您应该完全阅读文档并对Map的工作原理有深刻的理解,然后决定需要哪种类型的Map来满足您的要求。


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.

解决方案

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.

这篇关于如何在DataModel中使用HashMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 09:37