什么是迭代器和集合?这两个有关系吗?
// the interface definition
Interface Iterator {
boolean hasNext();
Object next(); // note "one-way" traffic
void remove();
}
// an example
public static void main (String[] args){
ArrayList cars = new ArrayList();
for (int i = 0; i < 12; i++)
cars.add (new Car());
Iterator it = cats.iterator();
while (it.hasNext())
System.out.println ((Car)it.next());
}
Run Code Online (Sandbox Code Playgroud)
Interface Iterator是否单独预定义了这些方法名称或用户定义了哪些方法名称?下面这四行实际上讲的是什么?
cars.add (new Car());
Iterator it = cats.iterator();
while (it.hasNext())
System.out.println ((Car)it.next());
Run Code Online (Sandbox Code Playgroud)
谢谢.我正在阅读一本收藏的书.
给出一个String列表
val www = List("http://bloomberg.com", "http://marketwatch.com");
Run Code Online (Sandbox Code Playgroud)
我想动态生成
<span id="span1">http://bloomberg.com</span>
<span id="span2">http://marketwatch.com</span>
def genSpan(web: String) = <span id="span1"> + web + </span>;
www.map(genSpan); // How can I pass the loop index?
Run Code Online (Sandbox Code Playgroud)
如何使用Scala map函数生成id(span1,span2),因为1和2是循环索引?或者唯一的方法是用于理解?
我有一个使用此功能的Google电子表格:
=SUM(E:E) - SUM(C:C)
Run Code Online (Sandbox Code Playgroud)
它将E列和C列的所有值相加,然后减去差值.如果差异为负,我希望能够返回0.
我试图使这需要的参数的方法Country.class,User.class等等,并返回argument.count().
我将为此方法提供的所有可能的类都扩展Model并拥有该方法count().
我的代码:
private static long <T> countModel(Model<T> clazz)
{
// there is other important stuff here, which prevents me from
// simply by-passing the method altogether.
return clazz.count();
}
Run Code Online (Sandbox Code Playgroud)
被称为:
renderArgs.put("countryCount", countModel(Country.class));
Run Code Online (Sandbox Code Playgroud)
然而,这根本不起作用.
我该怎么办?
有一个非常大的LOB silverlight应用程序,我们编写了很多自定义控件,这些控件在绘图时相当繁重.
所有数据都由RIA服务加载,处理并绑定(使用INofityPropertyChanged接口)到视图.
问题是第一次绘图需要花费很多时间.以下调用服务(服务器)和重绘是非常快的.
我使用Equatec profiler来跟踪问题.我看到处理只需几毫秒,所以我的想法是SL引擎的绘图很慢.
我想知道是否有可能在SL内部以某种方式描述进程以检查哪些绘图操作花费了太多时间.是否有任何指导如何更快地绘制复杂的自定义控件?
这似乎是游戏使用的一种技术,它将所有声音都放在一个文件中,纹理放在另一个文件中.这些文件通常达到GB大小.
这样做的原因是如何将子目录中的所有内容保存为小文件 - 许多小型游戏使用这种格式的一个,整体系统受到大公司的青睐?
是否有一些文件系统开销有很多小文件?他们是否试图保护自己的财产 - 尽管大多数似乎只是一个带有新扩展名的压缩文件?
举个例子,这里有一种方法可以得到一个包含 4 个(公平)骰子的所有可能结果的矩阵。
z <- as.matrix(expand.grid(c(1:6),c(1:6),c(1:6),c(1:6)))
Run Code Online (Sandbox Code Playgroud)
正如您可能已经理解的那样,我正在尝试解决一个已结束的问题,但在我看来,这是一个具有挑战性的问题。我使用计数技术来解决它(我的意思是手工),我最终得出了一些结果,子集之和为 5,等于 1296 中的 1083。该结果与提供给该问题的答案一致,在它关闭之前。我想知道如何使用 R 生成结果的子集(比如 z1,其中 dim(z1) = [1083,4] )。你有什么想法吗?
谢谢你。
typedef struct queue {
int q[max];
int qhead;
int qrear;
} queue;
void init_queue(queue *QUEUE)
{
QUEUE.qhead = 0;
QUEUE.qrear = -1;
}
void enqueue(queue *QUEUE,int data)
{
QUEUE.qrear++;
QUEUE.q[QUEUE.qrear] = data;
}
int process_queue(queue *QUEUE)
{
if(QUEUE.qhead > QUEUE.qrear)
return -1;
else
return QUEUE.q[QUEUE.qhead++];
}
Run Code Online (Sandbox Code Playgroud)
我正在使用数组实现队列只是为了保持简单.用上面的代码搞错了?
我有一个项目,我主要使用两个构建设置.不幸的是今天出了问题.一个编译而另一个没编译.如何比较XCode中的两个构建设置以查看差异是什么?
(对于那些感兴趣的人,我在一个版本中得到的错误是
jump to case label crosses initialization of 'const char* selectorName'
Run Code Online (Sandbox Code Playgroud)
如果你知道这意味着什么,我将非常感激)
我经常发现自己在做以下事情:
print "Input text: "
input = gets.strip
Run Code Online (Sandbox Code Playgroud)
有一种优雅的方式在一行中做到这一点吗?就像是:
puts "Input text: #{input = gets.strip}"
Run Code Online (Sandbox Code Playgroud)
这样做的问题是它在显示提示之前等待输入.有任何想法吗?
indexing ×2
java ×2
c ×1
casting ×1
collections ×1
data-files ×1
input ×1
iphone ×1
iterator ×1
loops ×1
map ×1
matrix ×1
objective-c ×1
performance ×1
pointers ×1
probability ×1
profiling ×1
queue ×1
r ×1
ruby ×1
scala ×1
silverlight ×1
statistics ×1
struct ×1
xcode ×1