在数组中查找特定的char元素

时间:2018-08-10 17:43:23

标签: java arrays char

我正在尝试在Array中找到第一个空格,以便可以预测单词的长度,并同时计算空格之前char个元素的数量。我总是遇到无限循环。

请帮助我。这是我的代码:

int counter=0;                      
int i=0;

while(counter==0) {
    if (field[i]==' ') {
        counter++;
    }
    else {
        if (i==field.length-1) {
            counter++;
        }
        else {
            i++;
        }
    }
}

2 个答案:

答案 0 :(得分:0)

如果必须在数组中找到第一个空格字符,则可以使用流API:

Boolean spacePresent = Arrays.stream(chars)
                             .anyMatch(it -> it == ' ')

答案 1 :(得分:0)

为什么要使用WHILE功能?我认为您可以执行以下操作:

import pandas as pd.  # You import the pandas library

input = pd.read_csv("input.csv") #your import csv
output = pd.read_csv("output.csv") #your export csv

input_array = list(input['#Name of column']) #use this if you know the name of the column
input_array = list(input.iloc[:,#index of column]) # use this if you know the index number of the column, index starts from 0

output = output.insert(loc=#the index you want; in this case 9 for the 10th column, column='Name of the new column', value=input_array) # you are inserting the array into output.csv

output.to_csv("path and output.csv",index = False) # we are writing a file, index = false means no new index row columns to be added.





import pandas as pd.  # You import the pandas library

input = pd.read_csv("input.csv") #your import csv
output = pd.read_csv("output.csv") #your export csv

input_array = list(input['Name of column']) #use this if you know the name of the column
input_array = list(input.iloc[:,0]) # Assuming input csv has only 1 column

output = output.insert(loc=9, column='New_column_name', value=input_array) # assuming the array is to be inserted into output.csv, column 10, in which case its 9 in pandas

output.to_csv("path and output.csv",index = False) # we are writing a file, index = false means no new index row columns to be added.