标签: arraylist

如何在没有循环的情况下顺序填充数组或arraylist?

我很惊讶我没有在任何地方找到答案.我想用1..100填充100的int数组.填充是一种很好的方法,但它不会在每个回合中增加值.它显然是如何用循环做的,但我想避免这种情况,因为我的最大值非常高.有没有api方法可以为我做这个?

java arrays arraylist fill

0
推荐指数
1
解决办法
2691
查看次数

在视图持有人文本视图中设置文本从arraylist

我正在实现列表视图,我有用户BaseAdapter class.i我试图从数组列表中的holder文本视图字段中setText但没有任何成功.Problem在getView方法的HashMap<String, ArrayList<String>> map = list.get(position); holder.txtFirst.setText(map.get(FIRST_COLUMN).toString()); 部分.
编辑: 我的主要活动类(postExecute方法),我在其中设置列表适配器类的键和值.代码如下:

protected void onPostExecute(ArrayList<ArrayList<String>> result) {

        ArrayList<String> conceptID = new ArrayList<String>(result.get(0));
        ArrayList<String> conceptDesc = new ArrayList<String>(result.get(1));

        listForSearchConcepts = new ArrayList<HashMap<String,ArrayList<String>>>();
        HashMap<String, ArrayList<String>> temp = new HashMap<String,ArrayList<String>>();
        temp.put(FIRST_COLUMN,conceptID);
        listForSearchConcepts.add(temp);
        temp.put(SECOND_COLUMN,conceptDesc);
        listForSearchConcepts.add(temp);
        listviewAdapter adapter = new listviewAdapter(MainActivity.this, listForSearchConcepts);
        listView.setAdapter(adapter);
    }`   
Run Code Online (Sandbox Code Playgroud)

但下面是我的适配器类代码:

public class listviewAdapter extends BaseAdapter
{
public ArrayList< HashMap < String,ArrayList < String > > > list;
Activity activity;

public listviewAdapter(Activity activity, ArrayList<HashMap<String,ArrayList<String>>> listForSearchConcepts) {
    super();
    this.activity = activity; …
Run Code Online (Sandbox Code Playgroud)

android arraylist hashmap baseadapter

0
推荐指数
1
解决办法
6482
查看次数

float的arraylist的arraylist的Java初始值

鉴于以下代码

ArrayList<ArrayList<Float>> fWordTagProb = new ArrayList<ArrayList<Float>>();
for(int f=0;f<pennTreeTags.size();f++)
    fWordTagProb.add(new ArrayList<Float>());
Run Code Online (Sandbox Code Playgroud)

这个二维阵列中每个"单元"的初始值是多少?它是零吗?

因此对于Integer类型它是一样的吗?

在此先感谢您的帮助

java arraylist

0
推荐指数
1
解决办法
557
查看次数

在Java中,如何有效地从ArrayList <StringBuilder>中删除重复?

我试图用来HashSet删除重复ArrayList<StringBuilder>.

例如,这是一个ArrayList,每一行都是一个StringBuilder对象.

"u12e5 u13a1 u1423"
"u145d"
"u12e5 u13a1 u1423"
"u3ab4 u1489"
Run Code Online (Sandbox Code Playgroud)

我想得到以下内容:

"u12e5 u13a1 u1423"
"u145d"
"u3ab4 u1489"
Run Code Online (Sandbox Code Playgroud)

我目前的实施是:

static void removeDuplication(ArrayList<StringBuilder> directCallList) {
    HashSet<StringBuilder> set = new HashSet<StringBuilder>();
    for(int i=0; i<directCallList.size()-1; i++) {
        if(set.contains(directCallList.get(i)) == false)
            set.add(directCallList.get(i));
    }   
    StringBuilder lastString = directCallList.get(directCallList.size()-1);
    directCallList.clear();
    directCallList.addAll(set);
    directCallList.add(lastString);
} 
Run Code Online (Sandbox Code Playgroud)

但随着ArrayList规模的扩大,性能变得越来越差.这个实现有什么问题吗?或者你在表现方面有更好的表现吗?

java arrays stringbuilder arraylist duplicate-removal

0
推荐指数
1
解决办法
908
查看次数

修改ArrayList中的对象

我需要一个动态的"数据库"对象,经过一番研究,决定使用ArrayList.但是,我无法使用以下代码修改arraylist:

public static ArrayList cprofiles;
...
cprofiles = new ArrayList();
...
...
Customer newc = new Customer (lna, fna, sinum, year, month, day);
cprofiles.add (newc);
Run Code Online (Sandbox Code Playgroud)

在此声明之后,我尝试使用以下格式调用对象内的方法,cprofiles.get(0).getName()但我收到错误说明

找不到符号(指向.getName())

当我尝试编译程序时.我花了大约一个小时来研究在ArrayList中修改它的正确方法,但是我发现的来源似乎暗示我正在做的事情确实是正确的.请帮助我发现我的错误以及如何解决它.

谢谢!

java database arrays oop arraylist

0
推荐指数
1
解决办法
101
查看次数

与ArrayList不兼容的类型错误

在我的Java类中,我定义了以下属性:

private ArrayList requests;
Run Code Online (Sandbox Code Playgroud)

这是类中的构造函数:

public LeaveRecord() {
    this.requests = new ArrayList<Request>();
    this.daysLeft = ALLOWANCE;
}
Run Code Online (Sandbox Code Playgroud)

在另一种方法中,我试图Request根据ArrayList的索引返回相关对象.

public Request getRequestAt(int index) {
    try {
        return this.requests.get(index);
    } catch (IndexOutOfBoundsException e) {
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我在返回行(上面代码段中的第3行)上收到了一个错误,说它需要leaverecord.Request但是找到了java.lang.Object.

我不知道会出现什么问题,因为我将ArrayList定义为类型Request.

有人能指出我正确的方向吗?谢谢.

java types arraylist

0
推荐指数
1
解决办法
806
查看次数

Java中的哈希表覆盖问题

我正在研究java,我无法使用put将数据添加到Java哈希表中.

我有这个代码

double finalIDF = 0.0;
double finalIDF = 0.0;
double finalBM = 0.0;

ArrayList<Double> finalTMlist = new ArrayList<Double>();
 Hashtable<String, ArrayList<Double>> BM25TFIDF = new Hashtable<String, ArrayList<Double>>();
 String[] bm25QueryList // this is the array to store strings like {hey , good , by}

 for(int finalindex = 0; finalindex < bm25QueryList.length ; finalindex++)
{
actualTFvalueforEachDoc.clear();
finalTMlist.clear();
finalIDF = 0.0;
finalIDF = htBM25IDF.get(bm25QueryList[finalindex]);
finalTMlist = tfForAlldoc.get(bm25QueryList[finalindex]);


 for(int innerfinal = 0 ; innerfinal < finalTMlist.size() ; innerfinal++ ){
 finalTM =finalTMlist.get(innerfinal);
finalBM = …
Run Code Online (Sandbox Code Playgroud)

java hashtable arraylist overwrite

0
推荐指数
1
解决办法
323
查看次数

java增加数组中的维度

是否有可能(我确定它是)并且不太复杂,无法制作动态多维数组,如果需要可以增加维数?

// Array[] 1 has 2 dimensions
if(blah=blah)
{
   Array[] 1 gets second dimension and is now Array[][]
}
Run Code Online (Sandbox Code Playgroud)

java arraylist dimensions multidimensional-array

0
推荐指数
1
解决办法
112
查看次数

对几个"链接"列表进行排序

我有3个列表,所以它们的元素顺序很重要:

names: [a, b, c, d]
files: [a-file, b-file, c-file, d-file]
counts: [a-count, b-count, c-count, d-count]
Run Code Online (Sandbox Code Playgroud)

我需要根据元素按字母顺序对它们进行排序List<String> names.
有人能解释我怎么做吗?

java sorting list arraylist

0
推荐指数
1
解决办法
128
查看次数

没有从数组中取正确的值

我想定义一个包含一堆字符串的数组.

然后我希望能够在数组中引用不同的字符串.听起来很简单,但是使用下面的代码,我将为变量onOneClick返回"to be"(即数组中的第二个字符串)(应该引用第一个字符串或"to implicate").

有任何想法吗?

String hintsList[] = {"to implicate", "to be", "to bite", "to draw", "to run", "to go", "to escape", "to fall", "to accept", "to open", "to laugh", "to listen", "to open", "to dance", "to use", "to save (not waste)", "to create"};

final String onOneClick = hintsList[1];
final EditText box0101 = (EditText)findViewById(R.id.box0101);

        box0101.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            txtHint.setText(onOneClick);                
        }
    });
Run Code Online (Sandbox Code Playgroud)

java arrays android arraylist settext

0
推荐指数
1
解决办法
74
查看次数