好的,我正在制作一个 CD 收藏程序,一切都很顺利,因为我按照我的课程进行,但后来我遇到了想让它显示在 jTextArea 中的问题。我敢打赌有一个简单的解决方案,但我找不到。我对此很陌生,任何答案都将不胜感激,我也在这里寻找答案,但没有发现我理解的任何内容。
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jButton1.setEnabled(true);
jButton2.setEnabled(false);
jButton3.setEnabled(false);
jButton4.setEnabled(false); //buttons
ArrayList<String> CD = new ArrayList(); //list
Collections.addAll(CD, "\nEd Sheeran - X\n", "\nNirvana - Nevermind\n", "\nShania Twain - Up!\n", "\nLights - Little Machines\n", "\nTaylor Swift - 1989\n"); //PreAdded CDs
Collections.sort(CD);
jTextArea1.setText(CD); //it works if i do System.out.println(CD) ? I need it to go to jTextArea1 though.
Run Code Online (Sandbox Code Playgroud) 创建包含字符串和数字的数组或列表的最佳方法是什么?
使用Dictionary,可以这样做:
Dictionary < string, int > dict = new Dictionary < string, int > ();
Run Code Online (Sandbox Code Playgroud)
但是有更好的方法使用Array或List吗?
我需要它来存储IP地址和相应的端口号.
我有一台服务器和几个客户端。我为每个客户端创建了一个线程。我想将每个客户端的线程或对象存储在arraylist中。并对其进行操作。
ArrayList<Client> clients;
Thread client = new Thread(new ClientThread(socket));
Run Code Online (Sandbox Code Playgroud)
想要在客户端的数组列表中添加每个客户端。我已经建立了一个客户端对象arraylist。
在关于ArrayList的javadoc中,您可以阅读有关方法add(E e)的内容,其中e是一个元素.元素和对象之间的区别是什么?我感兴趣的是元素与Java中的对象有何不同,而不是泛型.
我有一个对象类Product,如下所示
public class Product {
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
int price;
String id;
String image;
}
Run Code Online (Sandbox Code Playgroud)
我想根据价格对产品进行分类.我的阵列是
List<Product> …Run Code Online (Sandbox Code Playgroud) ArrayList<String> strings=new ArrayList<String>();
strings.add("h");
strings.add("e");
strings.add("l");
strings.add("l");
strings.add("o");
Run Code Online (Sandbox Code Playgroud)
下一个陈述是 strings.add(strings.remove(strings.size()-1)+"C");
然后输出结果是[h,e,l,l,oC],
所以我想知道为什么strings.add(strings.remove(strings.size()-1)+"C")得到这个结果,
我有一个接受a String和String<List>as方法参数的Java方法.如何区分String和不属于List?
方法:
void returnValues(String sensor, List<String> attributes)
Run Code Online (Sandbox Code Playgroud)
呼叫:
nexaConnect.returnValues(Arrays.asList("19455746", "blobJson", "deviceMfg", "eventCode", "sensorClass", "sensorUUID", "timeStamp", "uID"));
Run Code Online (Sandbox Code Playgroud)
我能看到的唯一可能的工作是删除第一个String并在List中包含值,然后获取列表的第一个值并以这种方式使用它.有没有办法将它们分开,以便它不是列表的一部分?
如果值为0,我必须删除Object.通过使用此代码,只删除了几个,但有些则没有.
public static List<DataEntityInteger> removeZeroValue(List<DataEntityInteger> list) {
for (int a=0; a<list.size(); a++) {
DataEntityInteger entityInteger = list.get(a);
if (entityInteger.getValue() == 0) {
list.remove(a);
}
}
return list;
}
Run Code Online (Sandbox Code Playgroud)
DataEntityInteger 类:
public class DataEntityInteger {
@SerializedName("keyname")
@Expose
private String keyname;
@SerializedName("value")
@Expose
private Integer value;
public String getKeyname() {
return keyname;
}
public void setKeyname(String keyname) {
this.keyname = keyname;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,如何删除所有零值对象ArrayList?
如果scoreArray中对象的值小于scoreArray中的任何其他对象,我想删除该值.但是我不知道如何在循环中删除ArrayList对象.
ArrayList<Integer> scoreArray = new ArrayList<Integer>();
for (int k = 0; k < people ; k++) {
int compare = scoreArray.get(k);
for (int j = 0; j < people; j++) {
if(compare < scoreArray.get(j)){
//scoreArray.remove(k);
}
}
}
Run Code Online (Sandbox Code Playgroud) 如何在Arraylist Android中添加项目
我有模型(没有构造函数,有setter和getter)
private int user_id;
private String firstname;
private String lastname;
private String pic;
Run Code Online (Sandbox Code Playgroud)
和我的代码
List<MeModel> meModels = new ArrayList<>();
meModels.clear();
meModels.get(0).setFirstname("Hello");
meModels.get(0).setLastname("World");
Run Code Online (Sandbox Code Playgroud)
它不起作用。
如何添加这个,谢谢!