arraylist

Two ArrayList one RecyclerView Adapter

為{幸葍}努か 提交于 2019-12-29 06:31:15
问题 I have a chat screen where i can chat with other user, i am sending chat data (message,time and sender via List) to RecyclerAdapter which populate chat views with data.Now i have one more List which has data with different layout. Like this Here is my method from where i am calling second arraylist into RecyclerAdapter public void TransferResultTo_Activity(List<Image_data_Wrapper> list) { Log.d(TAG,"Here is data Result From AsyncTask "+list.size()); getResult=list; Image_data_Wrapper Image

convert ArrayList.toString() back to ArrayList in one call

送分小仙女□ 提交于 2019-12-29 06:15:07
问题 I have a toString() representation of an ArrayList . Copying the toString() value to clipboard, I want to copy it back into my IDE editor, and create the ArrayList instance in one line. In fact, what I'm really doing is this: my ArrayList.toString() has data I need to setup a unit test. I want to copy this ArrayList.toString() into my editor to build a test against this edge case I don't want to parse anything by hand My input looks like this: [15.82, 15.870000000000001, 15.92, 16.32, 16.32,

How to add element in List while iterating in java?

こ雲淡風輕ζ 提交于 2019-12-29 04:59:51
问题 Say I have a List like: List<String> list = new ArrayList<>(); list.add("a"); list.add("h"); list.add("f"); list.add("s"); While iterating through this list I want to add an element at the end of the list. But I don't want to iterate through the newly added elements that is I want to iterate up to the initial size of the list. for (String s : list) /* Here I want to add new element if needed while iterating */ Can anybody suggest me how can I do this? 回答1: You can't use a foreach statement

Is it better to use a TreeSet or ArrayList when using a custom comparator

那年仲夏 提交于 2019-12-29 04:53:05
问题 I have implemented a graph. I want to sort a given subset of vertices with respect to their degrees. Therefore, I've written a custom comparator named DegreeComparator . private class DegreeComparator implements Comparator<Integer> { @Override public int compare(Integer arg0, Integer arg1) { if(adj[arg1].size() == adj[arg0].size()) return arg1 - arg0; else return adj[arg1].size() - adj[arg0].size()); } } So, which one of the below is more efficient? Using TreeSet public Collection<Integer>

How to iterate Arraylist<HashMap<String,String>>?

霸气de小男生 提交于 2019-12-29 04:24:27
问题 I have an ArrayList object like this: ArrayList<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>(); How to iterate through the list? I want to display the value in a TextView which comes from the data of ArrayList object. 回答1: Simplest is to iterate over all the HashMap s in the ArrayList and then iterate over all the keys in the Map : TextView view = (TextView) view.findViewById(R.id.view); for (HashMap<String, String> map : data) for (Entry<String, String> entry : map

Convert List<String> to List<Integer> directly

浪尽此生 提交于 2019-12-29 04:05:08
问题 After parsing my file " s" contains AttributeGet:1,16,10106,10111 So I need to get all the numbers after colon in the attributeIDGet List. I know there are several ways to do it. But is there any way we can Directly convert List<String> to List<Integer> . As the below code complains about Type mismatch, so I tried to do the Integer.parseInt, but I guess this will not work for List. Here s is String. private static List<Integer> attributeIDGet = new ArrayList<Integer>(); if(s.contains(

Reason for - List list = new ArrayList(); [duplicate]

怎甘沉沦 提交于 2019-12-29 03:00:18
问题 This question already has answers here : Why do some people use the List base class to instantiate a new ArrayList? (4 answers) What does it mean to “program to an interface”? (31 answers) Closed 6 years ago . I've seen code like this many times: List<String> list = new ArrayList<String>(); Why do people take the parent of ArrayList (and other classes) instead of the type of the generated object? Does that take less performance? Or why should someone do this? 回答1: When someone writes code

C# 泛型

南笙酒味 提交于 2019-12-29 02:36:31
泛型(generic)是C#语言.0和通用语言运行时(CLR)的一个新特性。泛型为.NET框架引入了类型参数(type parameters)的概念。类型参数使得设计类和方法时,不必确定一个或多个具体参数,具体参数可延迟到客户代码中声明、实现。这意味着使用泛型的类型参数T, 写一个类MyList<T>,客户代码可以这样调用:MyList<int>, MyList<string>或 MyList<MyClass> 。这避免了运行时类型转换或装箱操作的代价和风险。 ++++++++++++++++++++++++++++++++++++ + 概述: 泛型类和泛型方法兼复用性、类型安全和高效率于一身,是与之对应的非泛型的类和方法所不及。 泛型广泛用于 容器(collections) 和对容器操作的方法中。 .NET框架.0的类库提供一个新的命名空间System.Collections.Generic,其中包含了一些新的基于泛型的容器类。要查找新的泛型容器类(collection classes)的示例代码,请参见基础类库中的泛型。 当然,你也可以创建自己的泛型类和方法,以提供你自己的泛化的方案和设计模式,这是类型安全且高效的。下面的示例代码以一个简单的泛型链表类作为示范。(多数情况下,推荐使用由.NET框架类库提供的List<T>类,而不是创建自己的表。)类型参数T在多处使用

Show New List from ListActivity's Item Click Event

与世无争的帅哥 提交于 2019-12-29 02:06:09
问题 package com.comboyz.TantaGo; import android.app.ListActivity; import android.os.Bundle; import android.widget.ArrayAdapter; public class startMenu extends ListActivity{ @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setListAdapter(new ArrayAdapter <String>(this,R.layout.startmenu,category)); } static final String [] category= new String []{ "cinema","restuarnt","hotel","cafe","women shoping","men shoping" }

Java 高效代码50例

时光总嘲笑我的痴心妄想 提交于 2019-12-28 17:33:53
导读   世界上只有两种物质:高效率和低效率;世界上只有两种人:高效率的人和低效率的人。----萧伯纳 常量&变量 直接赋值常量,禁止声明新对象   直接赋值常量值,只是创建了一个对象引用,而这个对象引用指向常量值。 反例 Long i= new Long(1L ); String s = new String("abc"); 正例 Long i=1L ; String s ="abc"; 当成员变量值无需改变时,尽量定义为静态常量   在类的每个对象实例中,每个成员变量都有一份副本,而成员静态常量只有一份实例。 反例 public class HttpConnection{ private final long timeout=5L ; ... } 正例 public class HttpConnection{ private static final long timeout=5L ; ... } 尽量使用基本数据类型,避免自动装箱和拆箱   Java中的基本数据类型double、float、long、int、short、char、boolean,分别对应包装类Double、Float、Long、Integer、Short、Character、Boolean。   Jvm支持基本类型与对象包装类的自动转换,被称为自动装箱和拆箱。装箱和拆箱都是需要CPU和内存资源的