简体   繁体   English

为什么 ListIterator 与 Stream 的区别

[英]Why the difference with ListIterator vs Stream

We have a Dictionary txt file we converted to a String[ ] simpleArray我们有一个 Dictionary txt 文件,我们将其转换为 String[ ] simpleArray
We seldom work with array's so this one was beyond our comfort zone我们很少使用阵列,所以这个超出了我们的舒适区
It has 466552 items in this format 40 abacterial它有这种格式的 466552 项 40 非细菌
When we checking for a misspelled word it is blazing fast当我们检查拼写错误的单词时,它的速度非常快
When we go back to the list and check for the correct spelling of a word we were using ListIterator当我们 go 回到列表并检查我们使用 ListIterator 的单词的正确拼写时
We found the results odd based on the search term根据搜索词,我们发现结果很奇怪
So we tried to use Java 8 Streams with filters and lambda所以我们尝试使用 Java 8 Streams with filters 和 lambda

Here are the results using the ListIterator with the search term "some"这是使用带有搜索词“some”的 ListIterator 的结果

somebodies someday somegate someonell someone's Somerdale somersaulting somebody someday somegate someonell 某人的 Somerdale 翻筋斗
somerseted Somersetshire Somersville somesthesis somet sometime someway萨默塞特萨默塞特郡萨默斯维尔somesthesis somet sometime someway
somewhatly somewhen somewheres somewhiles somic有时 有时 有时 有时 有时


Here are the results using the ListIterator with the search term "someo" and "someon"这是使用带有搜索词“someo”“someon”的 ListIterator 的结果


someone'll somepart有人会分开


Here are the results using the Steams with filters and lambda the search term is "someon"这是使用带有过滤器的 Steams 和 lambda 的结果,搜索词是“someon”

someone someonell someone'll someones someone's某人某人某人某人某人某人某人


The question is have we constructed the ListIterator code correctly?问题是我们是否正确构建了 ListIterator 代码?
While the code runs it dose not produce reliable results虽然代码运行它不会产生可靠的结果

We would appreciate knowing if the Stream code could be constructed differently如果 Stream 代码可以以不同方式构造,我们将不胜感激
The goal was to add the items to a listview for now the results are in a textarea目标是现在将项目添加到列表视图中,结果在文本区域中
We have not used the listview before我们之前没有使用过listview


}if(found != true){

for(indexSC = 0; indexSC < simpleArray.length;indexSC++){
if(simpleArray[indexSC].toLowerCase().contains(txtTest.getText().trim().toLowerCase())){
// array stream foreach filter results to textarea javafx
List<String> cs = Arrays.asList(simpleArray);

ArrayList list = new ArrayList<>();
cs.stream().filter(s -> s.startsWith("someon"))
  //.forEach(System.out::println); 
.forEach(list :: add);   
String aL = list.toString();
System.out.println("!!!! aL "+aL);
String La = list.toString().replace("[", "").replace("]","").replace(",", " ");
System.out.println("@@@@ Stream "+La);

txaML.appendText(La);
txaML.appendText("\n");
//list.forEach(System.out::println);


ListIterator<String> listItr = cs.listIterator();
System.out.println("%%%% Second Find "+simpleArray[indexSC]+" At indexSC "+indexSC+" L "+simpleArray[indexSC].length());
txaML.clear();
while(listItr.hasNext()){
    if(listItr.next().startsWith("someon")){

        txaML.appendText(listItr.next());
        txaML.appendText("\n");
        //txaML.appendText(listItr.next().intern());
        //txaML.appendText("\n");
        System.out.println("!!!! ListIterator "+listItr.next());
        //System.out.println("!!!!!! Next intern "+listItr.next().intern());

    }  
}

We would appreciate knowing if the Stream code could be constructed differently如果 Stream 代码可以以不同方式构造,我们将不胜感激

We added a few item to your project namely a ComboBox and a ListView我们在您的项目中添加了一些项目,即 ComboBox 和 ListView
Why?为什么? If you plan on selecting the information generated by the Stream the TextArea is a real bear when it comes to selecting items (Text)如果您打算选择 Stream 生成的信息,那么在选择项目时,TextArea 是一个真正的熊(文本)
We noticed that you had an ArrayList list that the Stream added data to我们注意到您有一个 ArrayList 列表,Stream 将数据添加到
So no need for all that replace code.所以不需要所有替换代码。 We added a SelectionModel listener to the ListView我们向 ListView 添加了一个 SelectionModel 侦听器

Here is the code with your old remnant code这是带有旧剩余代码的代码
This is all you need for the ComboBox这就是 ComboBox 所需的一切

 public void CboSelect(){
 months = FXCollections.observableArrayList();
}

@FXML
public void getSP(){
    String selected = cboSP.getValue().toString();
    System.out.println("S S S selected "+selected); 
}

Here is the new work of Art ha ha这是艺术的新作品哈哈

        }if(found != true){

        lvListView.setStyle("-fx-font-size:18.0;-fx-background-color: white;");
        for(indexSC = 0; indexSC < simpleArray.length;indexSC++){
        if(simpleArray[indexSC].toLowerCase().contains(txtTest.getText().trim().toLowerCase())){
        // array stream foreach filter results to textarea javafx
        List<String> cs = Arrays.asList(simpleArray);

        ArrayList list = new ArrayList<>();
        cs.stream().filter(s -> s.startsWith("someon"))
          //.forEach(System.out::println); 
        .forEach(list :: add);   
        //String aL = list.toString();
        //System.out.println("!!!! aL "+aL);
        //La = list.toString().replace("[", "").replace("]","").replace(",", "").replace(" ", "\n");
        int L = list.size();
        for(int X = 0; X < L;X++){
        String A = (String) list.get(X);
        cboSP.getItems().add(A);
        txaML.appendText(A);
        txaML.appendText("\n");
        lvListView.getItems().add(A);
        System.out.println(" = = L "+L+" Num "+A);
        }

        lvListView.getSelectionModel().selectedItemProperty()
        .addListener((observable, oldValue, newValue) -> {
        System.out.println(newValue);});

We could not find much on the behavior of ListIterators with regards to performance我们找不到太多关于 ListIterators 在性能方面的行为
We looked a number of SO posts about Streams seems to be the new Java 8 thing我们看了一些关于 Streams 的 SO 帖子似乎是新的 Java 8 东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 迭代器和列表迭代器的区别? - Difference between Iterator and Listiterator? for (ListIterator<E> it = listIterator(); it.hasNext(); ) VS for (ListIterator<E> it = list.listIterator(); it.hasNext(); ) - for (ListIterator<E> it = listIterator(); it.hasNext(); ) VS for (ListIterator<E> it = list.listIterator(); it.hasNext(); ) Scala Stream与Java Stream Laziness的区别 - Scala Stream vs Java Stream Laziness Difference Collectors.toList()中的差异LongStream VS流 - Difference LongStream VS Stream in Collectors.toList() 为什么不在LinkedList中定义ListIterator的静态类? - Why not static class for the ListIterator defined in LinkedList? 为什么不使用ListIterator进行完整的LinkedList操作? - Why not use ListIterator for full LinkedList Operation? 为什么SynchronizedList的listIterator需要用户进行外部同步? - Why listIterator of SynchronizedList needs external synchronization by the user? 为什么ListIterator为LinkedList中的元素提供索引? - Why does ListIterator provide an index for elements in a LinkedList? 为什么Vector方法Iterator和ListIterator快速失败 - why Vector methods Iterator and ListIterator are fail fast 在java中toArray与stream.toArray有任何性能差异 - Is there any performance difference in toArray vs stream.toArray in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM