我有一个几行的数据表,每行有几列.
我想创建一个arraylist,将所有行都计算为一个字符串,
这样每个数组项都是这样{1;qwqww;qweqweqwe;qweqweqw;qwe}
的.字符串中的项将被分开,;
它是一个.NET 2解决方案
谢谢
在C#中,我需要能够在运行时基于逗号分隔的数据类型列表创建一个Type对象数组,这些数据类型作为字符串传递给函数.基本上,这是我想要完成的:
// create array of types
Type[] paramTypes = { typeof(uint), typeof(string), typeof(string), typeof(uint) };
Run Code Online (Sandbox Code Playgroud)
但我需要能够像这样调用我的函数:
MyFunction("uint, string, string, uint");
Run Code Online (Sandbox Code Playgroud)
并让它根据传入的字符串动态生成数组.这是我的第一次尝试:
void MyFunction(string dataTypes)
{
//out or in parameters of your function.
char[] charSeparators = new char[] {',', ' '};
string[] types = dataTypes.Split(charSeparators,
stringSplitOptions.RemoveEmptyEntries);
// create a list of data types for each argument
List<Type> listTypes = new List<Type>();
foreach (string t in types)
{
listTypes.Add(Type.GetType(t));
}
// convert the list to an array
Type [] paramTypes = listTypes.ToArray<Type>(); …Run Code Online (Sandbox Code Playgroud) 是否有任何方法可以一次性为我做以下事项:
List<String> list1 = new ArrayList<String>(Arrays.asList("A","B","C","D"));
List<String> list2 = new ArrayList<String>(Arrays.asList("B","C","E","F"));
List<String> list3 = new ArrayList<String>();
for(String element : list2){
if(!list1.contains(element))
list3.add(element);
}
Run Code Online (Sandbox Code Playgroud)
因此,list3应包含元素"E"和"F".
我尝试使用arraylist和简单的适配器向listview显示一些东西.我尝试了类似下面的内容,但在我的结果中显示了arraylist的姓氏.我错了,我无法理解.
final ListView listView = (ListView) findViewById(R.id.mylist);
ArrayList<HashMap<String, String>> list_of_bookmarks = new ArrayList<HashMap<String, String>>();
HashMap<String, String> b = new HashMap<String, String>();
String[] from = { "php_key","c_key","android_key","hacking_key" };
String[] name_of_bookmarks = { "php","c","android","hacking" };
for(int i=0;i<4;i++)
{
b.put(from[i],name_of_bookmarks[i]);
list_of_bookmarks.add(b);
}
};
int[] to = { R.id.txt1,R.id.txt1,R.id.txt1,R.id.txt1};
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), list_of_bookmarks, R.layout.list_layout, from, to);
listView.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
我只是想在列表视图中显示"php","c","android","hacking".什么应该是更有效的方式来做到这一点.我是一个初学者,所以你可以建议一个更好的方式,我应该遵循
我正在尝试创建ArrayLists的ArrayList.我想创建25个ArrayLists并使这些ArrayList保持不同的值.目标是按字长创建排序字典.
我的代码看起来像
for(int i = 0; i < 25; i++)
list2D.add(list);
for(int i = 0; i < stringList; i++)
list2D.get(stringList.get(i).length()).add(stringList.get(i))
Run Code Online (Sandbox Code Playgroud)
问题是每个列表在完成后都包含相同的值.
我知道问题发生的原因."list"是一个ArrayList,ArrayList是对象,如果你编辑一个对象,那么将编辑包含该对象的所有内容.
为了解决我试过的问题
for(int i = 0; i < 25; i++){
list = new ArrayList<String>();
for(int i2 = 0; i2 < stringList.size(); i2++){
if(stringList.get(i).length() == i)
list.add(stringList.get(i2));
}
list2D.add(list);
}
Run Code Online (Sandbox Code Playgroud)
但是当我测试我的"list2D"时
for(int i = 0; i < 25; i++)
System.out.print(list2D.get(i).size()+" ");
Run Code Online (Sandbox Code Playgroud)
我明白了
0 0 0 0 0 58110 0 58110 0 0 0 0 0 0 0 0 0 0 …
我有一个非常冗长的ArrayList,其中包含一些对象,但无疑是重复的.找到并删除这些重复项的最佳方法是什么.注意:我编写了一个布尔返回的compareObjects()方法.
我面临的问题是 - 在具有属性的onject中删除值.false
这是对象
var myObj={105:true,183:false,108:true,106:false}
Run Code Online (Sandbox Code Playgroud)
我可以使用以下逻辑获取数组中的值:
Object.keys(myObj)给人["105","183","108","106"]
但我需要一种方法来删除具有财产虚假和产生的价值["105",108"].可你能帮我吗?
我有104k字符串值,其中89k是唯一的.我想检查一下该列表中是否存在字符串.
这是我的类及其保存所有这些记录的方法.
public class TestClass {
private static TestClass singletonObj = null;
private List<String> stringList= null;
public static synchronized TestClass getInstance() {
if(singletonObj == null) {
singletonObj = new TestClass();
}
return singletonObj;
}
public boolean isValidString(String token) {
if(stringList == null) {
init();
}
if(stringList != null && token != null && !token.isEmpty())
return stringList.contains(token.toLowerCase());
return false;
}
private init() {
stringList = new ArrayList<String>();
// put all 104k values in this data structure.
}
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序尝试同时使用此isValidString()方法,每秒约20个请求.这工作正常但是当我尝试将数据结构更改为时 …
我的设置如下:在我的onCreate内部我初始化一个ArrayList,如下所示:
textList = new ArrayList<HashMap<String, String>>();
// unrelated code ...
if (isConnected()) {
new DisplayTextTask().execute(sectionId);
}
Run Code Online (Sandbox Code Playgroud)
并且AsyncTask通过提取文本HttpURLConnection(),使用解析json JsonReader,并将每行文本添加到textList(所有这些都发生在AsyncTask中doInBackground.我有一个自定义适配器,显示字符串在textList.
gotoNextSection()当用户想要导航到下一页时,我还有一个触发的功能,我在这里执行以下操作:
gotoNextSection() {
if (isConnected()) {
new DisplayTextTask().execute(sectionId+1);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,由于我不希望上一页中的陈旧文本保留在屏幕上,因此我在AsyncTask中执行以下操作:
private class DisplayTextTask extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
textList.clear();
}
@Override
protected String doInBackground(String... urls) {
// json parsing is called in getData()
try {
return getData(urls[0]);
} catch (IOException e) {
return "Could not load text"; …Run Code Online (Sandbox Code Playgroud) java android arraylist android-asynctask android-6.0-marshmallow
如何使用sense console或curl删除Elasticsearch中的arraylist值?
我想删除任何数组元素.?
POST /q/q/
{
"a": [
"z", "q", "1"
]
}
Run Code Online (Sandbox Code Playgroud)
它对我不起作用:
POST /q/q/AV4sjk40mWHLgYFNkmNd/_update
{
"script": {
"lang": "painless",
"inline": "ctx._source.a -=newsupp",
"params": {
"newsupp": "p"
}
}
}
Run Code Online (Sandbox Code Playgroud)
要么
POST /q/q/AV4sjk40mWHLgYFNkmNd/_update
{
"script": {
"lang": "painless",
"inline": "ctx._source.a.remove("1")"
}
}
Run Code Online (Sandbox Code Playgroud) arraylist ×10
java ×5
android ×2
arrays ×2
c# ×2
list ×2
angularjs ×1
api ×1
collections ×1
datatable ×1
duplicates ×1
hashset ×1
javascript ×1
listview ×1
object ×1
performance ×1
runtime ×1