Java排序列表

如何使用Collections.sort()或其他排序方法按字典顺序对Java列表进行排序? private List<List> possiblePoles = setPoles(); System.out.println(possiblePoles) [[1, 3, 5], [1, 2, 3]]

尝试打印链接名称时获取StaleElementReferenceException

我正在尝试打印谷歌搜索中显示的前5页链接..但是获取StateElementReferenceException不确定哪个出错了.. public class GoogleCoInTest { static WebDriver driver = null; public static void main(String[] args) throws InterruptedException { System.setProperty(“webdriver.gecko.driver”, “D:\\bala back up\\personel\\selenium\\Jars\\Drivers\\geckodriver.exe”); driver=new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get(“https://www.google.co.in/”); //driver.findElement(By.xpath(“//input[class=’gsfi’]”)).sendKeys(“Banduchode”);; WebElement search=driver.findElement(By.cssSelector(“input#lst-ib”)); search.sendKeys(“Banduchode”); search.sendKeys(Keys.ENTER); printLinksName(); List fiveLinks=driver.findElements(By.xpath(“.//*[@id=’nav’]/tbody/tr/td/a”)); for(int i=0;i<5;i++){ System.out.println(fiveLinks.get(i).getText()); fiveLinks.get(i).click(); Thread.sleep(5000); printLinksName(); } } public static void printLinksName() throws InterruptedException{ List allLinks=driver.findElements(By.xpath(“//*[@id=’rso’]/div/div/div/div/div/h3/a”)); System.out.println(allLinks.size()); //print all […]

使用流API查找列表中项目的所有索引

我正在尝试使用Java 8流和lambda表达式进行顺序搜索。 这是我的代码 List list = Arrays.asList(10, 6, 16, 46, 5, 16, 7); int search = 16; list.stream().filter(p -> p == search).forEachOrdered(e -> System.out.println(list.indexOf(e))); Output: 2 2 我知道list.indexOf(e)总是打印第一次出现的索引。 如何打印所有索引?

检查Selenium Java中是否可以单击元素

我是Selenium新手,需要检查元素是否可以在Selenium Java点击,因为element.click()会在link和label上传递。 我尝试使用下面的代码,但没有工作: WebDriverWait wait = new WebDriverWait(Scenario1Test.driver, 10); if(wait.until(ExpectedConditions.elementToBeClickable(By.xpath(“(//div[@id=’brandSlider’]/div[1]/div/div/div/img)[50]”)))==null) 需要帮助。

长变量的primefaces增量?

如果长变量声明为: – private volatile long counter = 0; 现在,如果我使用预增量运算符递增它,那么操作是primefaces的吗? 如果是,那么它会比java.util.concurrent.atomic.AtomicLong对象的增量更有效吗?

我可以限制另一个类可以在Java中调用的方法吗?

假设我有类A , B和C ,其中类C具有可读写属性: public class C { private int i = 0; // Writable. public void increment() { i++; } // Readable. public int getScore() { return i; } } 是否可以只让A使用increment()方法,只让B使用getScore()方法?

Spring Security不能与“hasRole(’ROLE_ADMIN’)”或ROLE_ADMIN一起使用

我使用的是Spring Security 4.1版。 如果我在安全配置中指定access=”hasRole(‘ROLE_ADMIN’)”或access=”ROLE_ADMIN” ,我可以登录,但是我无法访问我的管理页面。 以下是调试错误: DEBUG [http-bio-8080-exec-10] [org.springframework.security.web.access.intercept.FilterSecurityInterceptor] Secure object: FilterInvocation: URL: /admin; Attributes: [hasRole(‘ROLE_ADMIN’)] 2016-06-25 10:07:53,667 [] DEBUG [http-bio-8080-exec-10] [org.springframework.security.web.access.intercept.FilterSecurityInterceptor] Previously Authenticated: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@cc305a73: Principal: org.springframework.security.core.userdetails.User@74b46745: Username: francatore ; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_ADMIN ; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@166c8: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 7F702A6911A71EA5556C750B6D424FF5; Granted […]

Java编译错误:类Appletprac是公共的,应该在名为Appletprac.java的文件中声明

当我编译java程序时,我收到此错误:类Appletprac是公共的,应该在名为Appletprac.java的文件中Appletprac.java 这是我的java代码: import java.applet.*; import java.awt.*; // Graphics Class import javax.swing.*; import java.awt.event.*; /* */ public class Appletprac extends JApplet implements ActionListener { JButton OK; JRadioButton Font_Style1,Font_Style2,Font_Style3; ButtonGroup bg; JCheckBox Font_Family_Name; JTextField jt; int i; String s=””; public void init() { OK=new JButton(“OK”); Font_Family_Name=new JCheckBox(“Serif”); Font_Style1=new JRadioButton(“Plain”); Font_Style2=new JRadioButton(“Bold”); Font_Style3=new JRadioButton(“BoldItalic”); bg=new ButtonGroup(); jt=new JTextField(20); […]

使用该字符串调用的方法替换模式匹配的每个匹配项

我正在尝试做这样的事情: public String evaluateString(String s){ Pattern p = Pattern.compile(“someregex”); Matcher m = p.matcher(s); while(m.find()){ m.replaceCurrent(methodFoo(m.group())); } } 问题是没有replaceCurrent方法。 也许有一个我忽略的等价物。 基本上我想用匹配调用的方法的返回值替换每个匹配。 任何提示将不胜感激!

将BufferedImage复制到剪贴板

如何将BufferedImage存储到系统剪贴板中?