Skip to content

Tag: java

How to define a char stack?

How to define a char stack in java? For example, to create a String stack I can use such construction: But when I’m try to put char instead String I got an error: Answer Using a collection of char is pretty inefficient. (but it works) You could wrap a StringBuilder which is also a mutable collection of …

Why is there no SortedList in Java?

In Java there are the SortedSet and SortedMap interfaces. Both belong to the Java Collections framework and provide a sorted way to access the elements. However, in my understanding there is no SortedList in Java. You can use java.util.Collections.sort() to sort a list. Any idea why it is designed like that? …

calculate number of weeks in a given year

I would like to get the number of weeks in any given year. Even though 52 is accepted as a generalised worldwide answer, the calendars for 2015, 2020 and 2026 actually have 53 weeks. Is there any way that I can calculate this, or any functions that will help me out? Answer According to the wikipedia article o…

Java Generics and adding numbers together

I would like to generically add numbers in java. I’m running into difficulty because the Numbers class doesn’t really support what I want to do. What I’ve tried so far is this: Obviously this will not work. How can I go about correcting this code so I could be given a list of <int> or …