首页 \ 问答 \ 显示一个ArrayList?(Displaying an ArrayList?)

显示一个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"

相关问答

更多
  • 您可以使用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级对象? 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 ...
  • 应该: 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 ...
  • 注意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有空格,因此您需要将它放在反引号之间。 然后,为 ...
  • (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) ...
  • 问题是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("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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。