我试图从对象的ArrayList(.NET 1.1 Framework)中检索正确的值:
我有以下定义:
Public AlList As New ArrayList
Public Class ItemInfo
Public ItemNo As Int16
Public ItemType As String
Public Reports As Array
Public PDFs As Array
End Class
Run Code Online (Sandbox Code Playgroud)
form_load事件代码包含:
Dim AnItemObj As New ItemInfo
Run Code Online (Sandbox Code Playgroud)
然后循环包括:
AnItemObj.ItemNo = AFile.RecordId
AnItemObj.ItemType = temp
AlList.Add(AnItemObj)
Run Code Online (Sandbox Code Playgroud)
所以我现在应该有这些对象的ArrayList,但是如果我尝试检索数据:
MsgBox(AlList(5).ItemNo)
Run Code Online (Sandbox Code Playgroud)
我总是得到列表中最后一个值的ItemNo.
我错过了什么?
我的问题:我正在从JSP中的AJAX函数向servlet发送请求.
servlet处理数据并返回一个ArrayList.
我的问题是如何处理ArrayList内部AJAX,并将其作为一个表显示在同一个JSP中.
代码是
function ajaxFunction ( ) {
// var url= codeid.options[codeid.selectedIndex].text;
url="mstParts?caseNo=9&cdid=QCYST0020E1";
// alert(cid);
var httpRequest;
if (window.XMLHttpRequest) {
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
if (httpRequest == null){ alert('null');}
alert(url);
httpRequest.open("GET", url, true );
httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
//httpRequest.setRequestHeader('Content-Type', 'text/plain');
httpRequest.send(null);
alert('t1');
}
function alertContents(httpRequest) {
if (httpRequest.readyState == 4) {
var cType =httpRequest.getResponseHeader("Content-Type");
//document.write(httpRequest.toString());
// alert(cType);
// var xmlDoc=httpRequest.responseText;
//document.write(xmlDoc.toString());
// if …Run Code Online (Sandbox Code Playgroud) 我有这样的两倍ArrayList的java.
List<double[]> values = new ArrayList<double[]>(2);
Run Code Online (Sandbox Code Playgroud)
现在我想做的是通过循环在列表的零索引中添加5个值,在索引1中添加5个值.
第零个索引将具有值{100,100,100,100,100}
索引1将具有值{50,35,25,45,65}
并且所有这些值按以下顺序存储在双数组中
double[] values = {100,50,100,35,100,25,100,45,100,65}
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
在我的程序中,我需要跟踪打开到某个HTTP服务器的连接列表 - 以便在需要时立即断开它们.
我遇到了以下问题.如果我连接到HTTP服务器,一切都很完美,但如果是HTTPS,则不会从列表中删除连接.它会导致内存泄漏.
例:
package test;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
try {
ArrayList<URLConnection> al = new ArrayList<URLConnection>();
URL url = new URL("http://www.example.com");
URLConnection conn = url.openConnection();
al.add(conn);
System.out.println("Result of removing = " + al.remove(conn));
} catch (Exception ex) {
ex.printStackTrace(System.err);
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果URL指向" http://www.example.com ",则"删除结果= true".
但如果URL指向" https://www.example.com ",则"删除结果= false".
我不明白这种行为.我有一些假设,但不是不确定......
有人可以帮忙吗?
我对Java很新,我对方法调用转换有疑问.
我已经创建了一个新类,它扩展了名为ListableList的ArrayList - 但这似乎不是问题所在.
问题是我有一个看起来像这样的方法
public static void printList(ListableList<Listable> list, String seperator){
for(Listable item : list){
System.out.println(seperator);
System.out.println(item.toList());
}
System.out.println(seperator);
}
Run Code Online (Sandbox Code Playgroud)
我这样称呼这个方法:
Output.printList(rules, "..");
Run Code Online (Sandbox Code Playgroud)
规则初始化为
rules = new ListableList<Rule>();
Run Code Online (Sandbox Code Playgroud)
而Rule实现了Listable.
当我尝试编译时,我得到:
required: ListableList<Listable>,String
found: ListableList<Rule>,String
reason: actual argument ListableList<Rule> cannot be converted to ListableList<Listable> by method invocation conversion
Run Code Online (Sandbox Code Playgroud)
从我所学到的,为什么这应该起作用?提前致谢:)
我所问的可能是一个愚蠢的问题所以请原谅我.所以它是这样的:
List<Boss> bossList = new ArrayList<Boss>();
Boss b = null;
for(Employee e : List<Employee> myList){
b = new Boss();
b.setEmployee(e);
bossList.add(b);
b = null;
}
Run Code Online (Sandbox Code Playgroud)
所以在上面的场景中,我创建了很多Boss对象,然后取消引用它们(我知道我不需要写"b = null",但为了清楚我的问题,我这样做了).在正常情况下,我会将它们标记为垃圾收集,通过执行此操作,但因为在这种情况下,我在List集合中添加了那些Boss对象,它们是否标记为GC?如果不是那么为什么?List集合如何在内部工作以保存每个添加的Object的引用,以避免垃圾回收?
[EDIT]
Run Code Online (Sandbox Code Playgroud)
问题的范围仅限于for循环中创建的各个Boss对象,考虑到此方法将List的引用返回给外部世界.
以下是如何创建的两种方法ArrayList:
List<String/*or other object*/> arrList = new ArrayList();//Imports List, ArrayList
ArrayList<String/*or other object*/> arrList = new ArrayList();//Imports just ArrayList
Run Code Online (Sandbox Code Playgroud)
有什么不同?应该使用哪种方法?
我ArrayIndexOutOfBoundsException随机出现了.它似乎发生在我notifyDataSetChanged();身上因为错误是如此随机,所以很难准确指出它发生的位置.
有没有人有类似的自定义问题Adaptor?
FATAL EXCEPTION: main
java.lang.ArrayIndexOutOfBoundsException: length=12; index=12
at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:8041)
at android.widget.ListView.layoutChildren(ListView.java:1604)
at android.widget.AbsListView.onLayout(AbsListView.java:2444)
at android.view.View.layout(View.java:15221)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
at android.view.View.layout(View.java:15221)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:15221)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:15221)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:15221)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
at android.view.View.layout(View.java:15221)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:15221)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2260)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2007)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6364)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
at android.view.Choreographer.doCallbacks(Choreographer.java:591) …Run Code Online (Sandbox Code Playgroud) 我想保存表单的所有数据.
我的表格有这些元素 -
(使用Postman插件)
我的控制器是这样的 -
[HttpPost]
public async Task<IActionResult> Insert(IFormCollection data)
{
return Ok(data);
}
Run Code Online (Sandbox Code Playgroud)
所以,我得到这样的东西 -
[
{
"key": "user_id",
"value": [
"'12'"
]
},
{
"key": "title",
"value": [
"123"
]
},
{
"key": "text[]",
"value": [
"werwer",
"ghj"
]
}
]
Run Code Online (Sandbox Code Playgroud)
我想获得文本的价值.
所以,对于这种情况 -
"werwer",
"ghj"
Run Code Online (Sandbox Code Playgroud)
所以,我尝试过这样的事情 -
foreach (string description in data["text"])
{
// description => empty
}
Run Code Online (Sandbox Code Playgroud)
并试过这个 -
data.text
Run Code Online (Sandbox Code Playgroud)
并且-
data->text
Run Code Online (Sandbox Code Playgroud)
但没有什么对我有用.
有人可以帮忙吗?
在此先感谢您的帮助.
asp.net asp.net-mvc arraylist multidimensional-array asp.net-core-1.0
我不想开始另一个毫无意义的火焰战争,关于Java或C++是否是更好的语言.我想知道我为特定任务做的比较是否公平,测量数据是否正确.
我们需要决定是否将Java或C++用于我们的下一个项目.我在C++阵营,但我想为我的案子提供坚实的论据.我们的应用是特殊的,具有以下需求:
我用C++和Java实现了一个玩具程序.首先,我介绍C++版本:
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
struct Point{
float x, y;
};
int main(int argc, char*argv[]){
int n = atoi(argv[1]);
vector<Point>arr;
for(int i=0; i<n; ++i){
Point p;
p.x = i;
p.y = i+0.5f;
arr.push_back(p);
}
float dotp = 0;
for(int i=0; i<n; ++i)
dotp += arr[i].x * arr[i].y;
cout << dotp << endl;
}
Run Code Online (Sandbox Code Playgroud)
接下来是执行相同操作的Java版本:
import java.util.*;
class Point{
public float x, y;
} …Run Code Online (Sandbox Code Playgroud) arraylist ×10
java ×7
android ×2
ajax ×1
arrays ×1
asp.net ×1
asp.net-mvc ×1
c++ ×1
collections ×1
interface ×1
jsp ×1
list ×1
performance ×1
servlets ×1
vb.net ×1