kotlin和java和hashmap转换

为了解决WiFi扫描结果重复的问题,采用了将扫描到的WiFi信息存储到HashMap中以实现去重。通过遍历List,将WiFi信息转化为Map,利用HashMap的特性过滤重复项。随后,遍历HashMap,筛选符合条件的WiFi信息存入新的List,最终展示这个不含重复项的WiFi列表,实现实时扫描显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

碰到一个需求,扫描wifi,然后把扫到的wifi显示在list中,但是扫出来的wifi总是重复,为了实现去重效果,把list遍历,存储成map,然后利用map自身的特性,达到去重的目的,然后拿到不重复的map wifi列表,然后再次遍历map,把符合条件的wifi信息,存储到新的list中,然后展示这个list,可以实现wifi列表实时扫描显示
step1:

package com.example.demoanalytic

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.text.TextUtils
import android.util.Log

class MapTestActivity : AppCompatActivity() {
   
    //     private HashMap<String, StudentBean> map2 = new HashMap<>();
    private var map2: HashMap<String, StudentBean> = HashMap<String, StudentBean>()

    private var wifiList = mutableListOf<StudentBean>()

    private val wifi = "mindor-"

    override fun onCreate(savedInstanceState: Bundle?) {
   
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        /*
                map2.put("1", mStudentBean);
        map2.put("2", mStudentBean2);
        * */

        val mStudentBean = StudentBean()
        val mStudentBean2 = StudentBean()
        val mStudentBean3 = StudentBean()


        mStudentBean.age = 18
        mStudentBean.name = "郭靖"

        mStudentBean2.age = 22
        mStudentBean2
"小口算"通常是指一款教育软件或应用,它可能涉及到一些算法、图形用户界面(GUI)设计、数据结构(比如用于存储题目和答案的数据结构)、以及可能的在线评测功能等技术。为了编写这样的应用程序,我们需要使用到C++的一些关键部分: 1. **Qt** 或其他GUI库:用于构建交互式的窗口和界面元素,包括显示题目、接收用户输入和显示结果。 ```cpp #include <QApplication> // Qt基础库的一部分 #include <QLabel> // 创建窗口并添加显示口算题目的标签 int main(int argc, char *argv[]) { QApplication app(argc, argv); QLabel *questionLabel = new QLabel("计算 5 + 7", &app); // ...更多界面设置和布局代码 return app.exec(); } ``` 2. **线程**:如果要实现实时的计算反馈,可能需要在后台线程进行口算,避免阻塞主线程。 ```cpp QThread *thread = new QThread; Calculator worker; // 假设Calculator是处理计算的任务类 worker.moveToThread(thread); // 将计算任务移动到新线程 connect(thread, &QThread::started, &worker, &Calculator::startCalculation); connect(&worker, &Calculator::resultReady, this, &MainWindow::displayResult); thread->start(); // 开始计算 ``` 3. **数据结构**:用数组、列表或者队列来存储题目和答案,确保高效操作。 ```cpp std::vector<int> problems; // 存储口算题目 std::vector<int> answers; // 存储正确答案 // 添加题目 problems.push_back(5); problems.push_back(7); // 计算结果 int result = worker.calculate(problems.back()); answers.push_back(result); ``` 4. **错误处理和评估**:检查用户输入是否有效,根据算法规则评分。 ```cpp bool isValidInput(const QString &input) { // 检查输入是否为数字字符串并转换为整数 } int evaluateAnswer(int userAnswer, int correctAnswer) { if (isValidInput(userAnswer)) { return (userAnswer == correctAnswer) ? score : wrongAnswerScore; } else { return invalidInputScore; } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值