ACCOUNT p1= new SavingAccount("Saving","Ahmad",10000,3000,"43");
ACCOUNT p2= new CheckingAccount("Checking","Ali",20000,0 ,"0021");
ACCOUNT p3= new CheckingAccount("Checking","Mona",15000,0 ,"0033");
ArrayList <ACCOUNT> A
我使用eclipse android
我需要在ArrayList中建立索引或查找对象
public class myclass
{
int id;
int count;
String value;
}
mainactivity
{
ArrayList<myclass> list = new ArrayList<myclass>();
myclass mc = new myclass();
mc.id=1;
mc.count=20;
mc.value="my value 1"
lis
我希望在下面的代码中提供一些帮助:
// Remove last element
// Convert array to List for remove easily last item
List<String> listToRemove = new ArrayList<>(Arrays.asList(strings));
// Calculate index of last element & Remove them
int index = listToRemove.size();
index = index - 1;
System.out.println(
我需要你的帮助,你能告诉我在ArrayList中add()和set()有什么区别吗?我写了一个程序,用set()和add()试着找出来试着找出有什么不同我在网上搜索但找不到合适的答案
public class arraylistDemo
{
public static void main(String[] args) throws Exception
{
ArrayList al = new ArrayList();
al.add(10);
al.add("A");
al.add("B"
嗨,我将结果存储在数组列表中,这些结果是通过在java中查询不同的数据库而获得的。我需要比较这个数组列表,以获得公共行
List name = new ArrayList();
name.add(Spreadsheets.getString("Name"));
List namedb = new ArrayList();
namedb .add(rs.getString("eName"))
在c++中,我们使用strcmp进行比较。但是在java中,我如何比较这个数组列表,它应该返回公共行。或者我如何应用二进制搜
我有一个Arraylist,其中我想从arraylist中删除单个top元素(即POP In Stack),我使用了.Remove()方法,但是它不起作用,所以我如何从数组列表中只删除单个元素
例如,如果arraytlist包含96,97,98,99,100当使用.RemoveAt(0)它将删除元素96,我想从数组中删除项目100,那么如何删除这个最上面的项呢?
我有一个ArrayList类型的播放器,我正在寻找一个特定的字符串,我遇到了很多麻烦。
目前,如果播放机包含字符串,则使用布尔值来查看。然后使用for循环搜索列表。
但是它不断地输出文件的最后一行;我很确定我没有正确地搜索。
String playerName = sc.next();
boolean isFound = players.contains(playerName);
int index = 0;
for (int i = 0; i < players.size(); i++) {
if (isFound) {
我搜索了许多网站,但我发现的唯一一件事就是。
我有一个BSNode课程。我做了一个ArrayList<BSNode> data,现在我想交换两个变量,但是我面临这样的错误:
The type of the expression must be an array type but it resolved to ArrayList<BSNode>
有什么办法可以把这两样换掉吗?当我只想比较两个变量时,我只需在BSNode类中实现可比较的方法,然后重写一个方法。但是,我应该如何在数组列表中交换它们呢?
我有这样的方法:
public static void permutati
我有一个包含不同运动项目的数组列表。我创建了我的for循环来通过数组列表进行搜索,然后我必须将元素从gfList复制到gfResult,我将传递给activity。最后是我的array-list。我不知道我必须在哪里传递我的结果,在switch语句中,还是在每个活动的私有void部分中,以及应该如何传递。提前感谢!以下是我的代码,我有但不起作用:
GroupedFeed findFeed(String locateSport){
if ((!gfList.isEmpty())){
public static void m
我需要在Java类中重写equals()和hashCode()方法。但是这个类包含一个对象列表。如何通过比较ArrayList字段来实现代码的部分?
代码看起来像:
public class FirstClass {
private List<SecondClass> list = new ArrayList<>();
equals() {
//how i should implement equals for list field?
}
hashCode() {
}
}
我只能补充
我看到了如何通过它的值传递一个Arraylist,这样被调用的方法就不会修改原始的ArrayList。然而,试图传递一个本身包含其他Arraylist的ArrayList,即Arraylist的Arraylist。
public class Test {
public static void main(String[] args){
ArrayList<ArrayList<Integer>> lists = new ArrayList<ArrayList<Integer>>();
for(int j=0;j<2;j++
我试过搜索WWW但没能找到答案。在这里也找不到一个。
下面是我的问题:如何获得特定的名称(元素)?从ArrayList的客户那里?我想象它看起来是这样的:
ArrayList<Customer> list = new ArrayList();
String name = list.get(2) // which would return the Customer at 2's place.
但是,如果我想按名字搜索一个客户,比如一个名为Alex的客户呢?我该怎么做?
附加问题:我如何删除该客户?
这段代码创建了50个介于1和100之间的随机数,并将其添加到ArrayList中。现在我想在ArrayList中搜索相同的数字,然后删除它们并获得一个新的数字。最后,该列表应该只包含50个介于1和100之间的唯一数字。 问题是:我不知道,如何在相同的ArrayList中搜索相同的号码,删除它并获得一个新的号码。谁能帮帮我? import java.util.Random;
import java.util.ArrayList;
class RandomPrim {
public static void main(String[] args) {
Random n
我试图在ListView中实现搜索。我的ListView由HashMap在ArrayList中组成,我设法实现了逻辑,但我想每次文本更改时,我的方法中都会有很多对象和内存分配。因此,我正在寻找更少的内存分配逻辑,以便在ListView中使用HashMap在ArrayList中进行搜索。
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
//textlength = searchBar.getTex
我有一个城市清单,想从这些城市中搜索:
ArrayList myCities; // list of cities
String searchString = scanner.nextLine();
List<String> matchedCities = new ArrayList(); // an empty list for storing matched cities
for (String c : myCities) {
if (c.matches("(?i)" + searchString + ".*")) {
我正在使用查找“数组”数据类型中的关键字。
但是它只通过数组中的第一个字符串进行搜索。如何在数组中的所有字符串中搜索?
public static void getNews(final Context context, final Handler handler, final int page) {
ArrayList<String> catSearch = new ArrayList<>();
ArrayList<NewsCategory> categories = Cache.getNewsCategories(context);
我想在Arraylist保存到数据库时设置它的数据类型。例如:我对字符串变量使用注释,当它被保存到数据库中时,它的数据类型是文本
@Column(columnDefinition = "TEXT")
String matKhau;
所以,我不知道用ArrayList做同样的事情的任何方法,比如:
@CollectionOfElements
//add some annotation to set data type in here
ArrayList<String> ghiChu = new ArrayList<String>();
因为我将越南语字符串
我的目标是从ArrayList创建MenuItems,然后向每个菜单项添加一个事件,该事件在数组列表中搜索所选的菜单项,以便可以将其转移到下一个场景。菜单项将位于菜单按钮内。 MenuButton selectAccount = new MenuButton("Select an Account");
selectAccount.setMaxWidth(Double.MAX_VALUE);
for (int i = 0; i < accountList.size(); i++) {
//add the items. accou