显示一个ArrayList?(Displaying an ArrayList?)
ArrayList <String> cdcollection = new ArrayList(); private void initButtonActionPerformed(java.awt.event.ActionEvent evt) { Collections.addAll(cdcollection, "small", "mayre", "brown", "evner", "rain" ); initButton.setEnabled(false); } private void displayButtonActionPerformed(java.awt.event.ActionEvent evt) { for (int i = 0; i < cdcollection.size(); i++) { mainTextArea.setText(cdcollection.get(i)); } } private void addButtonActionPerformed(java.awt.event.ActionEvent evt) { cdcollection.add(cdtitleInput.getText()); } private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) { cdcollection.remove(cdcollection.size()-1); }
当我运行这个,并单击显示按钮时,只有最后一个CD标题(雨)出现...我怎样才能让所有五个CD标题出现在每一行?
ArrayList <String> cdcollection = new ArrayList(); private void initButtonActionPerformed(java.awt.event.ActionEvent evt) { Collections.addAll(cdcollection, "small", "mayre", "brown", "evner", "rain" ); initButton.setEnabled(false); } private void displayButtonActionPerformed(java.awt.event.ActionEvent evt) { for (int i = 0; i < cdcollection.size(); i++) { mainTextArea.setText(cdcollection.get(i)); } } private void addButtonActionPerformed(java.awt.event.ActionEvent evt) { cdcollection.add(cdtitleInput.getText()); } private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) { cdcollection.remove(cdcollection.size()-1); }
When I run this and click the display button only the last cd title (rain) appears... How can I get all five cd titles to appear each on one line?
原文:https://stackoverflow.com/questions/10688928
更新时间:2022-01-30 12:01
最满意答案
为什么不在一次操作中执行它而不是通过chron级对象?
Time2<-as.POSIXct(paste(bigdata$Date, bigdata$Time), format= "%d.%m.%Y %H:%M:%S") ########## bigdata <- read.table(text=" Date Time Current 1 28.02.2013 23:58:50 NA 2 28.02.2013 23:58:50 0.3 3 28.02.2013 23:58:51 0.3 4 28.02.2013 23:58:51 0.3 5 28.02.2013 23:58:57 0.3 6 28.02.2013 23:58:58 0.3", header=TRUE, stringsAsFactors=FALSE) library("chron") Time<-chron(bigdata$Date, bigdata$Time, format= c(dates= "d.m.y", times="h:m:s")) Time2<- as.POSIXct(paste(as.Date(dates(Time)),times(Time)%%1)) Time2 [1] "2013-02-28 23:58:50 PST" "2013-02-28 23:58:50 PST" "2013-02-28 23:58:51 PST" [4] "2013-02-28 23:58:51 PST" "2013-02-28 23:58:57 PST" "2013-02-28 23:58:58 PST"
Why not instead just do it in one operation and not go through a chron-class object?
Time2<-as.POSIXct(paste(bigdata$Date, bigdata$Time), format= "%d.%m.%Y %H:%M:%S") ########## bigdata <- read.table(text=" Date Time Current 1 28.02.2013 23:58:50 NA 2 28.02.2013 23:58:50 0.3 3 28.02.2013 23:58:51 0.3 4 28.02.2013 23:58:51 0.3 5 28.02.2013 23:58:57 0.3 6 28.02.2013 23:58:58 0.3", header=TRUE, stringsAsFactors=FALSE) library("chron") Time<-chron(bigdata$Date, bigdata$Time, format= c(dates= "d.m.y", times="h:m:s")) Time2<- as.POSIXct(paste(as.Date(dates(Time)),times(Time)%%1)) Time2 [1] "2013-02-28 23:58:50 PST" "2013-02-28 23:58:50 PST" "2013-02-28 23:58:51 PST" [4] "2013-02-28 23:58:51 PST" "2013-02-28 23:58:57 PST" "2013-02-28 23:58:58 PST"
相关问答
更多-
从POSIXct提取时间(Extracting time from POSIXct)[2022-04-18]
您可以使用strftime将数据时间转换为任何字符格式: > t <- strftime(times, format="%H:%M:%S") > t [1] "02:06:49" "03:37:07" "00:22:45" "00:24:35" "03:09:57" "03:10:41" [7] "05:05:57" "07:39:39" "06:47:56" "07:56:36" 但是,这并不是很有帮助,因为你想绘制你的数据。 一个解决方法是从您的时间中删除date元素,然后在所有时间添加相同的日期 ... -
除非在format参数中指定,否则时区必须是分开的。 您的代码将时区嵌入字符串中,但默认格式为"%Y-%m-%d"和"%Y/%m/%d" ,因此时区会被截断,默认为当前时区语言环境。 我们可以在attr()找到a的时区,因为它是a的一个属性。 table(a == as.POSIXct("2016-06-27", tz = attr(a, "tzone"))) # FALSE TRUE # 18 2 The time zone needs to be separate, unless ...
-
Chron到POSIXct(Chron to POSIXct)[2023-09-12]
为什么不在一次操作中执行它而不是通过chron级对象? Time2<-as.POSIXct(paste(bigdata$Date, bigdata$Time), format= "%d.%m.%Y %H:%M:%S") ########## bigdata <- read.table(text=" Date Time Current 1 28.02.2013 23:58:50 ... -
这是一个单一的命令---但你想as.POSIXlt() : R> as.POSIXlt(Sys.Date()) [1] "2016-03-02 UTC" R> format(as.POSIXlt(Sys.Date()), "%Y-%m-%d %H:%M:%S") [1] "2016-03-02 00:00:00" R> 只有当转换为POSIXct发生时区偏移到UTC(对我来说是六个小时)时才会进入: R> as.POSIXct(Sys.Date()) [1] "2016-03-01 18:00:00 C ...
-
R使用POSIXct时出错(R error while using POSIXct)[2024-02-26]
应该: data.raw=read.csv(file=file.choose(),header=TRUE,sep=";",row.names=NULL)%>% mutate(date.re = as.POSIXct(date, format = "%d/%m/%Y")) sep是不同的“;” Should be: data.raw=read.csv(file=file.choose(),header=TRUE,sep=";",row.names=NULL)%>% mutate(date.re = as.P ... -
转换为posixct失败(converting to posixct fails)[2022-09-13]
注意str(resulttable[3,1])的输出。 它表示它是类data.table和data.frame的对象。 因此,您必须使用标准提取操作符提取要转换为POSIXct的一列或多列。 resulttable[3, 1][[1]] # a vector resulttable[3, 1]$`UTC FORECAST TIME` # the same vector 请注意,列名称UTC FORECAST TIME有空格,因此您需要将它放在反引号之间。 然后,为 ... -
与chron融化(melt with chron)[2024-04-28]
(1)我假设你在运行显示的代码之前发出了这个命令: library(reshape2) 在这种情况下,您可以使用reshape包。 它不会导致此问题: library(reshape) 其他解决方案是 (2)使用R的reshape功能: reshape(direction = "long", data = x, varying = list(2:3), v.names = "Var") (3)或将chron列转换为数字,使用reshape2包中的melt然后转换回: library(reshape2) ... -
sqldf和POSIXct(sqldf and POSIXct)[2022-04-23]
问题是SQLite没有日期时间类型。 R将POSIXct对象存储为自1970-01-01(Epoch)以来的秒数,并且由于没有相应的类型,因此它将作为原始秒数(即一个数字)发送,因此将此对象发送到SQLite时。 当它在处理后被发回给R时,它仍然只是一个数字。 有几种方法可以处理这个问题: 1)列名赋予与POSIXct名称相同的输出列名称。 sqldf有一个启发式方法,它在其中查看输入和输出列名称,如果它们中的任何一个匹配,则它假定输出应转换为该名称的输入列所具有的相同类。 sqldf("select mi ... -
你试一试: x <- chron(dates="05/12/15", times="12:30:45") y<-as.POSIXct(x) attr(y,"tzone")<-"GMT" y #[1] "2015-05-12 12:30:45 GMT" Just try: x <- chron(dates="05/12/15", times="12:30:45") y<-as.POSIXct(x) attr(y,"tzone")<-"GMT" y #[1] "2015-05-12 12:30:45 GMT" ...
-
as.POSIXct的奇怪行为(strange behavior of as.POSIXct)[2022-04-13]
正如我在评论中指出的那样,这里的解决方案就是使用 as.POSIXct("30/03/2014 2:00", format = "%d/%m/%Y %H:%M", tz = "GMT") GMT可以用您各自的时区替换。 正如您已经指出的那样,原因是从冬季到夏季的变化 介于两者之间 as.POSIXct("30/03/2014 2:00", format = "%d/%m/%Y %H:%M") 和 as.POSIXct("30/03/2014 2:59", format = "%d/%m/%Y %H:%M ...