java

Map集合循环遍历的几种方式

拟墨画扇 提交于 2021-02-19 08:11:45
package cn.jdbc.test; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; /** * Map 集合的循环遍历 * @data 2018.1.21 * */ public class TestMap { public static void main(String[] args) { Map<String, Object> map = new HashMap<String, Object>(); map.put("aaa", 111); map.put("bbb", 222); map.put("ccc", 333); map.put("ddd", 444); //Map集合循环遍历方式一 System.out.println("第一种:通过Map.keySet()遍历key和value:"); for(String key:map.keySet()){//keySet获取map集合key的集合 然后在遍历key即可 String value = map.get(key).toString();// System.out.println("key:"+key+" vlaue:"+value); } /

Starting threads from inside EDT event handler code in Swing apps

喜夏-厌秋 提交于 2021-02-19 08:11:26
问题 My understanding of the Swing Event Dispatcher Thread (EDT) is that its a dedicated thread where event handling code is executed. So, if my understanding is correct, then in the example below: private class ButtonClickListener implements ActionListener{ public void actionPerformed(ActionEvent e) { // START EDT String command = e.getActionCommand(); if( command.equals( "OK" )) { statusLabel.setText("Ok Button clicked."); } else if( command.equals( "Submit" ) ) { statusLabel.setText("Submit

Storing object into an array - Java

…衆ロ難τιáo~ 提交于 2021-02-19 08:09:11
问题 I am relatively new to Java and I have taken some light courses on it. I am trying to emulate an exercise that I had a while back and I am having some trouble. I have two classes. One is taking in data and the other is storing it. public class Car{ public Car(String name, String color) { this.name = name, this.color = color } How can I store this into the array (not an array list) that I created in this class: public class CarDatabase { Car[] carList = new Car[100]; public CarDatabase() { //

Reading RTF directly to a TextView on Android

99封情书 提交于 2021-02-19 08:09:06
问题 I have a RTF file saved in a database column, i need to read that text and display it with style into a TextView on the Android. From what i have searched, i didn't find how to read RTF directly on the android. What i have tried are: Searching for something to convert RTF to HTML (on the web service (C#) and on the Android) (I haven't found a suitable solution, found this but i didn't know how to use it... too many classes and i didn't know how to deal with it, i will try again until someone

EntityManager is null

巧了我就是萌 提交于 2021-02-19 08:08:12
问题 I am new to EJB, creating an application for fun/learning EJB following is the code. @Entity @Table(name = "PERSON", schema = "experiment") @NamedQuery(name = "Person.fetchAllPerson" , query = "select p from Person p") public class Person implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") private Long id; @Column(name = "name", length = 500) private String name; @Column(name = "age") private

ManyToOne annotation to specific column

£可爱£侵袭症+ 提交于 2021-02-19 08:06:43
问题 I am trying to create the follow structure using Hibernate with annotations: To create a ManyToMany relationship I had created two classes called SessionRiu and SessionRiuId (pk). This way the Session class has two foreign keys (agend_id and user_id) but when I try to create the OneToMany from operation the hibernate does not create the foreign using the id from session: Session FKs: Operation FKs ( empty ): As I am beginner in java and hibernate, I would appreciate any suggest about my code.

Removing invisible characters from the end of a Java String

冷暖自知 提交于 2021-02-19 08:02:11
问题 how can i find the last visible character in a Java String? I'd like to remove all line breaks and other invisible characters from a Java String Kind Regards, Tord 回答1: You can use the trim() method of the String class for removing trailing (and leading) white space and line breaks: String trimmed = original.trim(); 回答2: string_variable.replaceAll("\\p{C}", "?"); This will replace all non-printable characters. Where p{C} selects the invisible control characters and unused code points. 来源:

Removing invisible characters from the end of a Java String

☆樱花仙子☆ 提交于 2021-02-19 08:02:02
问题 how can i find the last visible character in a Java String? I'd like to remove all line breaks and other invisible characters from a Java String Kind Regards, Tord 回答1: You can use the trim() method of the String class for removing trailing (and leading) white space and line breaks: String trimmed = original.trim(); 回答2: string_variable.replaceAll("\\p{C}", "?"); This will replace all non-printable characters. Where p{C} selects the invisible control characters and unused code points. 来源:

Java generic method not working - parameter not being restricted [duplicate]

こ雲淡風輕ζ 提交于 2021-02-19 08:01:47
问题 This question already has answers here : Why does this generic java method accept two objects of different type? (4 answers) Closed 2 years ago . Say I have this code: class Demo { static <T> T pick(T a1, T a2) { return a2; } public static void main(String[] args) { pick("d", 123); } } From what I learned, it seems like I have stated that the two parameters a1 , a2 and the return type of pick must be under the same generic type T . So why is the compiler allowing me to pass a String and an

Java-DOM-Parser: Exception on Transformer.transform

徘徊边缘 提交于 2021-02-19 08:01:41
问题 I'm trying to solve a problem with the domparser since hour. I wrote a simple application to load a xml-file, modify them and write the changes back. It works until I switched converted the project to a maven-project. I'm not sure if thats the problem. I can't understand the exception Here my Code-Part for the DOM-parser: import java.io.File; import java.io.IOException; import javafx.beans.property.BooleanProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans