我用Java编写了一个小程序来查找句子中的重复单词.没有语法错误,没有复杂性错误,但是一旦运行它我就会得到一个奇怪的长错误.
class Find {
public static void main(String args[]) {
String M = "Hello World Hello Hello";
String[] words = M.split(" ");
for (int i = 0; i < M.length(); i++) {
for (int j = 0; j < M.length(); j++) {
if (words[i].equalsIgnoreCase(words[j])) {
System.out.printf("Duplicate Words :" + words[i], words[j]);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
运行时:
Duplicate Words :HelloDuplicate Words :HelloDuplicate Words :HelloException in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at Find.main(Find.java:9)
Run Code Online (Sandbox Code Playgroud)
我做错了什么?请帮忙.
好吧,我正在制作一个导航条的样本,一切都很好,除非嵌套的li悬停在背景中,背景并没有完全覆盖空间.
我的HTML代码如下:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css" />
<title>NavBar</title>
</head>
<body>
<div id="nav">
<ul>
<li><a href="#">Home</a></li><li>
<a href="#">About</a></li><li>
<a href="#">Contact</a>
<ul>
<li><a href="#">Email</a></li>
<li><a href="#">Phone</a></li>
</ul>
</li>
</ul>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我的CSS代码如下:
html, body {
margin: 100px;
padding:0px;
}
#nav {
margin: 0px;
padding: 0px;
background-color: #909090;
font-familY: Courier;
font-size: 19pt;
color: #afc0ff;
}
#nav ul ul {
display: none;
background-color: #909090;
}
#nav ul li:hover > ul{
margin: 0px;
padding:0px;
display:block;
position:absolute;
top: 100%;
left: …Run Code Online (Sandbox Code Playgroud) 我一直在尝试将双数组转换为数字用空格分隔的字符串.
public class StringTest {
public static void main(String[] args) {
double[] g = {1.2,1.4,1.4} ;
String d = StringUtils.join(g, " ");
System.out.println(d);
}
}
Run Code Online (Sandbox Code Playgroud)
Commons Lang javadoc告诉我有可能这样做,代码也可以运行,但我只[D@54a50a00打印出来.这里缺少什么?
我需要实现一个方法,使用泛型提供三个数字时计算最大数量.我知道如何使用Comparable类来执行此操作,但我只需要使用数字.
这是代码.
public static <T extends Math> T compareThreeValue(T x, T y, T z){
T max=Math.max(Math.max(x, y), z);
return max;
}
Run Code Online (Sandbox Code Playgroud)
我添加了这段代码,以了解我在尝试什么.
假设我有一个 C 类的对象 c(来自一个库,所以我不能修改类定义)它扩展了 Iterable。
在我的函数中,我想为用户提供一种处理类型 R 对象流的方法,其中类型 R 的对象是通过对类型 T 的对象进行转换获得的。
目前我执行以下操作:
Stream<R> f(...) {
C c = ...;
return StreamSupport.stream(c.spliterator(), false)
.map(...);
}
Run Code Online (Sandbox Code Playgroud)
它之所以有效是因为 spliterator 在类 Iterable 中默认实现,但 javadoc 说出于性能原因不建议使用默认实现。
如果用户只想处理或应用流操作,我想返回一个流而不创建列表。我对流的并行化属性不感兴趣,因为 c 中的对象只能以顺序方式读取。
所以我想知道,如果有的话,做这种事情的推荐方式是什么。简单地返回一个 List 还是传递一个消费者函数作为参数更好?我有点担心建议不要使用默认拆分器实现的 javadoc。使用上述方法,我可以确保保留底层 Stream 中元素出现的顺序吗?
我使用PrimeFaces日历表示日期范围(为此我使用两个日历).如何在运行时更改日期范围,以便第一个日历范围将小于或等于第二个日历值.例如时间范围:http://www.primefaces.org/showcase-ext/sections/timePicker/timeRange.jsf
我正在JSF中开发一个Web应用程序,我正在使用PrimeFaces条形图.我想改变传奇的位置.我验证了Primefaces:他们使用的帖子中的Charts和Legend位置,
<p:barChart id="stackedKWH"
value="#{kwhSalesBeanManager.kwhSalesChart}"
legendPosition="e" style="height:300px;width:800px"
title="kWh Sales by Type"
stacked="true"
barMargin="10"
min="0"
max="125000000"/>
Run Code Online (Sandbox Code Playgroud)
但在primeface 5.1中却没有 <p:barchart/>
<p:chart type="bar" model="#{chartView.barModel}" style="height:300px"/>
Run Code Online (Sandbox Code Playgroud)
我的输出看起来像,

预期产量:

我怎样才能做到这一点?有人建议我正确的方法吗?
我有以下导航规则:
<navigation-rule>
<from-view-id>/pages/*</from-view-id>
<navigation-case>
<from-outcome>test</from-outcome>
<to-view-id>/pages/test/edit.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
Run Code Online (Sandbox Code Playgroud)
TestMB:
public String test() {
return "test?id=1";
}
Run Code Online (Sandbox Code Playgroud)
和test.xhtml:
<h:commandLink action="#{testMB.test}">click</h:commandLink>
Run Code Online (Sandbox Code Playgroud)
但是,如果这是行不通的话return "test?id=1";.我不想使用return "/pages/test/edit.xhtml?id=1";,我想使用抽象名称test.
我在Firefox for Mac上使用Firebug,以便查看有关发送到服务器的请求数据的信息以及从服务器获取的响应.我的Spring + Hibernate + JSF + MySQL应用程序有问题; 即我不能将新对象持久化到数据库中.在Eclipse中,我有一个XHTML文件,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<title>JSF Spring Hibernate Integration</title>
<style type="text/css">
.tg {
border-collapse: separate;
border-spacing: 0;
border-color: #ccc;
}
.tg td {
font-family: Arial, sans-serif;
font-size: 14px;
padding: 10px 5px;
border-style: solid;
border-width: 1px;
overflow: hidden;
word-break: normal;
border-color: #ccc;
color: #333;
background-color: #fff;
}
.tg th {
font-family: Arial, sans-serif;
font-size: 14px;
font-weight: normal;
padding: 10px …Run Code Online (Sandbox Code Playgroud) 我想要一个UIComponent在 PrimeFaces 3.4 中通过 id 查找的方法。我已经找到了一个方法来执行此操作,但它有一个方法visitTree(在PrimeFaces 5.2中可用),该方法不适用于PrimeFaces 3.4。
请有人帮我在下面的 XHTML 中找到面板对象。
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<h:form id="form">
<p:panel id="pnl"><h:outputText value="Yahoooo...."></h:outputText></p:panel>
<p:commandButton ajax="false" value="Toggle" actionListener="#{myBean.mytoggle}"/>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
Primefaces 5.2工作方法
public UIComponent findComponent(final String id) {
FacesContext context = FacesContext.getCurrentInstance();
UIViewRoot root = context.getViewRoot();
final UIComponent[] found = new UIComponent[1];
root.visitTree(new FullVisitContext(context), new VisitCallback() {
@Override
public VisitResult visit(VisitContext context, UIComponent component) {
if(component.getId().equals(id)){
found[0] = component;
return VisitResult.COMPLETE;
}
return VisitResult.ACCEPT;
}
});
return …Run Code Online (Sandbox Code Playgroud)