java-6

Behaviour of String.split in java 1.6?

只愿长相守 提交于 2019-12-20 03:23:32
问题 My code is: String s = "1;;;; 23;;"; System.out.println(s.split(";").length); and gives as output 5 . The source code of split is: public String[] split(String regex) { return split(regex, 0); } and the documentation says: This method works as if by invoking the two-argument split(java.lang.String,int) method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array. The string "boo:and:foo", for example, yields the

How to generate end tag for empty element in XML using JAXB

99封情书 提交于 2019-12-19 17:36:42
问题 I'm generating XML using JAXB. But JAXB is generating an empty Tag closing it self. But my client want separate empty tag. I know both are equals but he is not agree with me. please any one suggest the solution. Thanks. Sample code: @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "currencyCode", "discountValue", "setPrice", "spendLowerThreshold", "spendUpperThreshold", "discountApportionmentPercent", "discountApportionmentValue" }) @XmlRootElement(name = "countryData")

Java 6 File Deletion

余生长醉 提交于 2019-12-19 13:45:31
问题 I am aware that this question is a raging duplicate of this question. However , I have now read that entire page twice, and some sections 3 times, and for the life of me I don't see how/where it is answered! So, on to my problem. I am at work and am stuck using Java 6 SE and cannot upgrade to 7. I am writing a program that creates a file, writes to it, does some processing, and then needs to delete the file out of existence. I am having the exact same problem as the person who asked the

intern() behaving differently in Java 6 and Java 7

回眸只為那壹抹淺笑 提交于 2019-12-17 07:10:13
问题 class Test { public static void main(String...args) { String s1 = "Good"; s1 = s1 + "morning"; System.out.println(s1.intern()); String s2 = "Goodmorning"; if (s1 == s2) { System.out.println("both are equal"); } } } This code produces different outputs in Java 6 and Java 7. In Java 6 the s1==s2 condition returns false and in Java 7 the s1==s2 returns true . Why? Why does this program produces different output in Java 6 and Java 7? 回答1: It seems that JDK7 process intern in a different way as

Using File.listFiles with FileNameExtensionFilter

倖福魔咒の 提交于 2019-12-17 02:24:49
问题 I would like to get a list of files with a specific extension in a directory. In the API (Java 6), I see a method File.listFiles(FileFilter) which would do this. Since I need a specific extension, I created a FileNameExtensionFilter . However I get a compilation error when I use listFiles with this. I assumed that since FileNameExtensionFilter implements FileFilter , I should be able to do this. Code follows: FileNameExtensionFilter filter = new FileNameExtensionFilter("text only","txt");

Why does Kotlin byte code reference java.util.function.BiConsumer?

三世轮回 提交于 2019-12-14 01:18:40
问题 From what I understand Kotlin should be able to run using JRE 6. But this code with a foreach on a map fails because of a reference to a Java 8 class ( java/util/function/BiConsumer ) CompilerTest.kt: fun main(args: Array<String>) { val aMap = mapOf("bar" to "bat") aMap.forEach { k, v -> println("$k -> $v")} } Compile the Kotlin code: » kotlinc CompilerTest.kt -jvm-target 1.6 -include-runtime -d compilerTest.jar Testing the compiled code on JRE 6: » docker run --rm -v "$PWD":/usr/src/myapp -w

Why TreeSet can be used as a key for TreeMap in jdk 1.6?

此生再无相见时 提交于 2019-12-13 18:42:58
问题 why does this: import java.util.*; public class my { public static void main(String[] a) { TreeMap<TreeSet<Integer>, String> map = new TreeMap<TreeSet<Integer>, String>(); TreeSet<Integer> set = new TreeSet<Integer>(); map.put(set, "lol"); } } work in Java 6? I mean that by specification putting TreeSet as a key of TreeMap without proper Comparator should lead to ClassCastException but it doesn't when running under Java 6. Was it a bug or there were some specification changes in Java 7 that

Implicit super constructor is undefined with Java Generics [duplicate]

▼魔方 西西 提交于 2019-12-13 07:52:34
问题 This question already has answers here : Java error: Implicit super constructor is undefined for default constructor (10 answers) Closed 6 years ago . I have the following base class and sub class: public class BaseClass<T> { public BaseClass(T value){ } public class NewClass<T> extends BaseClass<T> { public NewClass(T value){ } } I get the following error: Implicit super constructor BaseClass() is undefined. Must explicitly invoke another constructor How do I go about fixing this? 回答1:

Porting Arrays.copyOfRange from Java 6 to Java 5

被刻印的时光 ゝ 提交于 2019-12-13 02:56:24
问题 I have some source code that I need to make runnable under Java 5. Unfortunetly that code uses Arrays.copyOfRange function which was only introduced in Java 6. What would be the most effective way to implement same utility using only Java 5 API? 回答1: Check out the OpenJDK 6 page - it's open source Java. You can download and read the source code yourself, find out how it's implemented, and add the functionality to the app manually. 回答2: Here goes the code from OpenJDK for those who are

How do I nest layout managers without using swing classes/methods?

橙三吉。 提交于 2019-12-12 18:11:51
问题 I need to make an applet in Java 6, 640*480 pixels, with a toolbar on the bottom with some buttons, scrollbars, and labels. The best way I could think of was using a BorderLayout , making the BorderLayout.SOUTH region a GridBagLayout (which would contain the controls), and the rest of the BorderLayout area null, as a place for grapics to be drawn with the controls. I can't find any resources online that don't use swing, and I don't know anything about swing to deduce what they are doing or