标签: arraylist

Objective-C NSMutableArray套接字?

我想在ArrayList/NSMutableArray中存储几个套接字,但套接字的类型为int,NSMutableArray只接受对象(id).是否有其他数据类型可以用作套接字的容器?我不确定我会有多少条目,所以我希望数据容器就像一个ArrayList.

谢谢!

编辑:我已经尝试将套接字作为NSNumber发送,但是当我尝试使用套接字发送消息时,它无法正常工作并导致XCode崩溃.

sockets iphone arraylist objective-c nsmutablearray

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

在这种情况下如何使用迭代器?

我必须以这种方式迭代一个arraylist.

ArrayList<Integer> li = new ArrayList<Integer>();
li.add(20);
li.add(30);
li.add(40);
li.add(50);
li.add(70);

for (int i = 0; i < li.size() - 1; i++)
    System.out.println(li.get(i) + " " + li.get(i + 1));
Run Code Online (Sandbox Code Playgroud)

输出:

20 30
30 40
40 50
50 70
Run Code Online (Sandbox Code Playgroud)

如何使用迭代器做同样的事情?

java iterator arraylist

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

TicTacToe游戏的OutOfBoundsException; 问题:数组?

我是写一个井字游戏的开始.我刚刚运行它并得到以下堆栈跟踪:

 Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
 at java.util.ArrayList.rangeCheck(ArrayList.java:571)
 at java.util.ArrayList.get(ArrayList.java:349)
 at TicTacToe.isMarked(TicTacToe.java:23)
 at TicTacToe.mark(TicTacToe.java:59)
 at TicTacToe.main(TicTacToe.java:7)
Run Code Online (Sandbox Code Playgroud)

我怀疑这是我的ArrayList设置方式的问题?我在某处读到了导致问题的空值,但这是我第一次处理数组,所以我不熟悉这个主题.无论如何,这是我的代码:

    import java.util.*;

    public class TicTacToe {

    public static void main(String[] args) {
    newBoard();
    ******************System.out.println(mark(1));************
    System.out.println(mark(5));
    System.out.println(mark(9));
   }

 // Creates a blank board.
 public static ArrayList<String> newBoard() {
  ArrayList<String> board = new ArrayList<String>(8);
  return board;
 }

 // Returns true if the square has been marked.
 public static boolean isMarked(int numberOfSquare) {
  if (numberOfSquare > 9 || numberOfSquare < 1) { …
Run Code Online (Sandbox Code Playgroud)

java arrays exception-handling arraylist

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

ArrayList C++问题

我在互联网上找到了一个arraylist课程,网址是http://code.google.com/p/arraylist/downloads/detail?name=arraylist-v1.zip.

在使用MS Visual C++的Windows上编译很好,在OS X下使用GCC我遇到了大量错误.这是错误输出:

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/consolerpg
mkdir -p build/Debug/GNU-MacOSX
rm -f build/Debug/GNU-MacOSX/arraylist.operators.o.d
g++ -fpermissive   -c -g -MMD -MP -MF build/Debug/GNU-MacOSX/arraylist.operators.o.d -o build/Debug/GNU-MacOSX/arraylist.operators.o arraylist.operators.cpp
arraylist.operators.cpp:86: error: redefinition of 'datatype& arraylist<datatype>::operator[](int)'
arraylist.operators.cpp:86: error: 'datatype& arraylist<datatype>::operator[](int)' previously declared here
arraylist.operators.cpp:100: error: redefinition of 'const datatype& arraylist<datatype>::operator[](int) const'
arraylist.operators.cpp:100: error: 'const datatype& arraylist<datatype>::operator[](int) const' previously declared here
arraylist.operators.cpp:128: error: redefinition of 'const arraylist<datatype>& arraylist<datatype>::operator=(const arraylist<datatype>&)'
arraylist.operators.cpp:128: error: 'const arraylist<datatype>& arraylist<datatype>::operator=(const arraylist<datatype>&)' previously declared …
Run Code Online (Sandbox Code Playgroud)

c++ arrays gcc g++ arraylist

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

Java如何对Point对象的ArrayList进行排序

我正在使用Point Class来管理(x,y)坐标列表,我需要按X的顺序对它们进行排序.

我在线阅读创建一个实现Comparator的新类PointCompare,但是我不确定它是如何工作的,因此我在sortByXCoordinates方法中有一个编译器错误.

非常感谢帮助,欢迎任何评论,提前感谢.这是我的一些代码:

import javax.swing.JOptionPane;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
//import java.util.Iterator;

public class ConvexHullMain {

 private Point coordinates = new Point(0, 0);
 private final int MAX_POINTS = 3;
 private ArrayList<Point> coordinateList = new ArrayList<Point>();

 public void inputCoordinates() {

  String tempString; // temp string for JOptionPane
  int tempx = 0;
  int tempy = 0;

  for (int i = 0; i < MAX_POINTS; i++) {
   try {
    // input x coordinates
    tempString = JOptionPane.showInputDialog(null,
      "Enter X coordinate:"); …
Run Code Online (Sandbox Code Playgroud)

java sorting arraylist comparator

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

arrayList的remove方法不起作用

嗨,我已经写了这个代码,输出你可以得到该.remove()方法不起作用.a,b,c,和d一些Points对象有x和y成员.

以下是a and b and c and d值,必须删除if语句中的值,upper但不是.

X :59  Y: 143
X :165  Y: 140
X :59  Y: 143
X :165  Y: 140


   System.out.println(upper.toString());
        for(int i =0;i<upper.size();i++)

            if(upper.get(i)==a||upper.get(i)==b||upper.get(i)==c||upper.get(i)==d){
                upper.remove(i);

            }
        for(int i =0;i<lower.size();i++)

            if(lower.get(i)==a||lower.get(i)==b||lower.get(i)==c||lower.get(i)==d){
                upper.remove(i);
            }



        System.out.println(upper.toString());
        System.out.println(lower.toString());


   first println : [X :108  Y: 89, X :165  Y: 140]

   second println: [X :108  Y: 89, X :165  Y: 140] …
Run Code Online (Sandbox Code Playgroud)

java arraylist

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

Java中的ArrayList - 我的单行代码有什么问题?

我已经尝试将此与示例进行比较,我似乎无法找出为什么这不会编译,所以我希望有一些见解.

ArrayList<Integer> listOfPrimeNumbers(initialCapacity) = new ArrayList<Integer>( );
Run Code Online (Sandbox Code Playgroud)

是我的代码.我的理解是它创建了一个新的ArrayList对象,类型为Integer,名为listOfPrimeNumbers,并且具有我传入的参数的初始容量,称为initialCapacity.

不幸的是我得到了一个"';' 当我尝试编译时出现"错误" 有人可以帮忙吗?

java arraylist

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

如何确保数组中包含值?

以下是我的代码:

它用于测试素数生成器,它生成并填充arraylist前n个素数.在我的测试中,我创建了一个已知素数数组,然后使用我的方法构造前50个(knownPrimes.length)素数的arraylist.然后选择一个随机数,我想断言使用我的方法nextRandomPrime(从我的未知/生成素数的arraylist中选择一个数字)选择的每个素数都包含在数组knownPrimes中.我怎样才能做到这一点 ?

在伪代码中我想做的是:

assertTrue(createdPrimeList.nextRandomPrime is a value in the array knownPrimes);
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止所得到的:

 public void comparePrimes() {
    int[] knownPrimes = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 
      31,  37,  41,  43,  47,  53,  59,  61,  67,  71, 
      73,  79,  83,  89,  97, 101, 103, 107, 109, 113, 
      127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 
      179, 181, 191, 193, 197, 199, 211, 223, 227, 229 };

    Primes createdPrimeList = new Primes (knownPrimes.length); …
Run Code Online (Sandbox Code Playgroud)

java arrays arraylist

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

在父类的arraylist中区分每个子类

嗨,我有一个父类,Abstract Employee我有孩子Secretary, Engineer, Technician如果我有ArrayList<Employee> employees;和在一个for循环我随机做员工=新秘书或新工程师...

有没有办法知道谁是谁?如果这个问题没有得到很好的解答,我会为我的无知道歉.

java arraylist

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

我怎么能从这个清单中分离出来?

text = [('good', 'Title meta tag contains no errors.'), ('good', 'Title relevancy to page content is good.'), ('good', 'Description meta tag contains no errors.'), ('good', 'Description relevancy to page content is excellent.'), ('good', 'Keywords meta tag contains no errors.'), ('good', 'Keyword relevancy to page content is excellent.'), ('good', 'The Robots meta tag contains no errors.'), ('good', 'The Author meta tag contains no errors.'), ('good', 'The size of the web page.'), ('good', 'The web page load time.')]
Run Code Online (Sandbox Code Playgroud)

问题是如何将列表分开

text = ['good', …
Run Code Online (Sandbox Code Playgroud)

python list arraylist

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