我有一个Iterable Object。要将IntWriter转换为int,我们可以使用get()方法。有一种方法可以检索Iterable Intwriter对象的第一个值。我试过
Iterator<IntWritable> values;
values.get(0).get() //To retrieve the first value.
答案 0 :(得分:0)
你在找这个吗?
Iterator<IntWriteable> itr = iterable.iterator();
while (itr.hasNext()) {
System.out.println(itr.next().get());
break;
}
答案 1 :(得分:0)
使用番石榴:
Iterable<IntWritable> iterable = ...;
int first = Iterables.get(iterable, 0).get();
或Java8:
int value = StreamSupport.stream(iterable.spliterator(), false).findFirst().get().get();
答案 2 :(得分:0)
def toNumbers(sep):
changeNum = [float(x) for x in sep]
return changeNum
def sumlist(sep):
total = 0
sum(pls)
average = sum(pls)/len(sep)
print ("Your average is: ", average)
def main():
file = open('grades.txt','r')
for read in file:
sep = read.split(",")
sep = toNumbers(sep)
sumlist(sep)
main()