Tag: arraylist

Java比较两个列表的对象值?

我有两个列表* *ListA listA = new ArrayList() **和ListB listB = new ArrayList()都包含MyData和MyDatatypes的对象包含这些variables。 MyData { String name; boolean check; } ListA和ListB都包含MyData对象,现在我必须比较列表的对象值这里名称以及检查variables,如果ListA包含这些对象值 ListA = [“Ram”,true],[“Hariom”,true],[“Shiv”,true]; 和ListB也包含 ListB = [“Ram”,true],[“Hariom”,true],[“Shiv”,true]; 那么我必须比较列表,并返回false,因为这两个列表是相同的但是,如果ListA包含 ListA = [“Ram”,true],[“Hariom”,true],[“Shiv”,false]; 和ListB包含 ListB = [“Ram”,true],[“Hariom”,true],[“Shiv”,true]; 那么我必须比较列表并返回true,因为这两个列表不相同 反之亦然,所以任何列表值的任何轻微的变化,我必须返回true。 有一件事我不得不在这里提到对象可以以任何顺序。

Kotlin:null不能是非nulltypes的kotlin的值

如何将空值分配给Kotlin中的ArrayList ? 我正在尝试将null值添加到我的自定义ArrayList中 var mList = ArrayList() mList.add(null) 在Java中它可能,但我怎么能在Kotlin中实现这一点? 我正进入(状态 null不能是非空typeskotlin的值 我需要插入空值来在RecyclerView中加载更多的function

如何将自定义类的ArrayList转换为Java中的JsonArray?

我正在尝试将自定义类的ArrayList转换为JsonArray。 以下是我的代码。 它执行得很好,但是一些JsonArray元素即使是ArrayList中的数字也是零。 我试图把它们打印出来。 像ArrayList中的customerOne age是35,但是在JsonArray中是0。 什么可能是错的? ArrayList customerList = CustomerDB.selectAll(); Gson gson = new Gson(); JsonElement element = gson.toJsonTree(customerList , new TypeToken<List>() {}.getType()); JsonArray jsonArray = element.getAsJsonArray();

如何将数组列表中的特定项目移动到第一项

例如:一个列表 ABCDE 给定C,切换到 CABDE 注意数组的大小会改变,有些项目可能在运行时间被删除 Collections.swap(url, url.indexOf(itemToMove), 0); 这个语句是不行的,因为它输出CBADE不是CABDE,怎么解决? 谢谢。

如何在应用程序中打印数组列表?

如何在Android Studio的应用程序屏幕上显示ArrayList? 它显示: 必需:可编辑! 提供:数组列表 fun sort(view: View) { for (a in 0..myList.size) { if(myList[a]==null) myList[a]=0 } for(a in 0..myList.size) { val b=a var temp=0 for (c in b..0) { if(myList[c]< myList[c-1]) { temp=myList[c] myList[c]= myList[c-1] myList[c-1]=temp } } } ans.text= myList } 请帮忙解决问题。 我对Android Studio颇为陌生,刚刚开始学习如何在Kotlin中制作应用程序。 所以请试着用简单的话来回答。

Kotlin用集合中的lastOrNull()替换isEmpty()和last()

我想使用类似(代码如下),但我认为必须有使用lastOrNull()而不是使用isEmpty和last()的更好的解决方案, data class Entry(val x: Float, val y: Float) var entries: MutableList = ArrayList() if(some) { entries.add(Entry(100f, 200f) } val foo = (if (entries.isEmpty()) 0f else entries.last().y) + 100f 有没有更好的方法像entries.lastOrNull()?.y if null 0f ?

我怎样才能创建一个Kotlin像Java一样的数组呢?

我如何创建一个像我们在java中做的数组? int A[] = new int[N]; 我怎么能在Kotlin做到这一点?

如何添加从URL阅读到arraylist的内容

这是我的代码从URL读取内容,然后将其添加到一个数组列表。 当我调试它显示sb.append(行)获取字符串,但在此之后,ArrayList的数据大小= 0.所以这真的让我感到困惑,添加SB不起作用。 我怎么解决它? var arrayListData = ArrayList<String>() var config: Config = Config() inner class GetData: AsyncTask<Void, Void, ArrayList<String>>() { override fun doInBackground(vararg params: Void?): ArrayList<String> { val link = arrayOf(config.urlStatus, config.urlTongquan, config.urlBanggia) for (i in 0 until link.size){ getContentURL(link[i]) } return arrayListData } override fun onPostExecute(result: ArrayList<String>) { super.onPostExecute(result) Toast.makeText(this@MainActivity, result[1], Toast.LENGTH_SHORT).show() } } […]

我怎样才能创建一个Kotlin像Java一样的数组呢?

我如何创建一个像我们在java中做的数组? int A[] = new int[N]; 我怎么能在Kotlin做到这一点?

从ArrayList中删除偶数

我必须创建一个具有ArrayList的方法; 我需要从这个ArrayList中删除偶数。 我已经写了代码,但有一个逻辑错误,我无法识别。 这是我的代码: static void sortList(){ List <Integer> number=new ArrayList <Integer>(); number.add(11); number.add(45); number.add(12); number.add(32); number.add(36); System.out.println("Unsorted List: "+number); for (int i=0;i<number.size();i++){ int even=number.get(i)%2; if (even==0){ System.out.println("This is Even Number:"+ number.get(i)); number.remove(i); } } Collections.sort(number); System.out.println("Sorted List: "+number); } 代码的输出是: Unsorted List: [11, 45, 12, 32, 36] This is Even Number:12 This is Even […]