arraylist

Sort a list that contains a custom class

风格不统一 提交于 2021-02-04 13:48:30
问题 so I'm currently doing an exercise for college that has several optional parts (because we havn't done this in class yet), one of them being to use lists instead of arrays (so it'd be variable size) and another one printing the list sorted by points (I'll get to that now) So, I have the Player.java class which looks like this. public class Player { String name; String password; int chips; int points; public Player(String n, String pw, int c, int p) { name = n; password = pw; chips = c; points

Sort a list that contains a custom class

为君一笑 提交于 2021-02-04 13:47:12
问题 so I'm currently doing an exercise for college that has several optional parts (because we havn't done this in class yet), one of them being to use lists instead of arrays (so it'd be variable size) and another one printing the list sorted by points (I'll get to that now) So, I have the Player.java class which looks like this. public class Player { String name; String password; int chips; int points; public Player(String n, String pw, int c, int p) { name = n; password = pw; chips = c; points

Removing a character from an ArrayList of characters

空扰寡人 提交于 2021-02-04 13:07:55
问题 I am facing with this unwanted char to int conversion in a loop. Say I have this List of Characters and I want to remove one of those: List<Character> chars = new ArrayList<>(); chars.add('a'); chars.add('b'); chars.add('c'); chars.remove('a'); // or chars.remove('a'-'0'); so 'a' is interpreted as its int value and I'm getting an IndexOutOfBoundsException exception. Is there any easy workaround for this? 回答1: A char is promoted to an int , which takes precedence over autoboxing, so remove(int

Removing a character from an ArrayList of characters

柔情痞子 提交于 2021-02-04 13:07:21
问题 I am facing with this unwanted char to int conversion in a loop. Say I have this List of Characters and I want to remove one of those: List<Character> chars = new ArrayList<>(); chars.add('a'); chars.add('b'); chars.add('c'); chars.remove('a'); // or chars.remove('a'-'0'); so 'a' is interpreted as its int value and I'm getting an IndexOutOfBoundsException exception. Is there any easy workaround for this? 回答1: A char is promoted to an int , which takes precedence over autoboxing, so remove(int

Removing a character from an ArrayList of characters

主宰稳场 提交于 2021-02-04 13:07:14
问题 I am facing with this unwanted char to int conversion in a loop. Say I have this List of Characters and I want to remove one of those: List<Character> chars = new ArrayList<>(); chars.add('a'); chars.add('b'); chars.add('c'); chars.remove('a'); // or chars.remove('a'-'0'); so 'a' is interpreted as its int value and I'm getting an IndexOutOfBoundsException exception. Is there any easy workaround for this? 回答1: A char is promoted to an int , which takes precedence over autoboxing, so remove(int

Does modifying the result of a getter affect the object itself?

独自空忆成欢 提交于 2021-02-04 12:56:29
问题 I have a question about using getter methods in java. Suppose I had this class: class Test { private ArrayList<String> array = new ArrayList<String>(); public ArrayList getArray() { return this.array; } public void initArray() { array.add("Test 1"); array.add("Test 2"); } } class Start { public static void main(String args[]) { initArray(); getArray().remove(0); } } My question is: Would the actual arraylist object be modified ("Test 1" removed from it)? I think I have seen this in places,

Java Swing: Making a growing circle by mouse click on JPanel

你说的曾经没有我的故事 提交于 2021-01-29 22:39:32
问题 I'm a beginner in Java and this time I'm trying to learn more by finding code examples and editing them, for example from this website. I have a JFrame and each time it (or more precise the JPanel in it) is clicked on, a circle is drawn which will grow/expand outwards like a water ripple. Each circle starts with a certain radius and will be removed or redrawn when reaching a bigger radius (I chose radius "r" from 10 to 200). I have two programs for this which almost work but are missing

Java Swing: Making a growing circle by mouse click on JPanel

我的未来我决定 提交于 2021-01-29 22:26:05
问题 I'm a beginner in Java and this time I'm trying to learn more by finding code examples and editing them, for example from this website. I have a JFrame and each time it (or more precise the JPanel in it) is clicked on, a circle is drawn which will grow/expand outwards like a water ripple. Each circle starts with a certain radius and will be removed or redrawn when reaching a bigger radius (I chose radius "r" from 10 to 200). I have two programs for this which almost work but are missing

How to sort an ArrayList using a Map key as list object and value as the order?

偶尔善良 提交于 2021-01-29 16:22:00
问题 I need to keep the order of my list of objects as it can be changed and reordered anytime in my webapp. In my model I have a array list of objects example objectList = [object1, object2, object3, object4] and I save the order of each object belonging to this instance to a Map example: order { "object1":4, "object2":2, "object3":1, "object4":3 } Therefore i want to sort my array according to its value in the map retrieved by the objects Id as the key: Expected result: [object3, object2,

How to create a list with different type of data using vb.net?

强颜欢笑 提交于 2021-01-29 09:34:30
问题 I need to create a list with different datatypes element, for example: {{10, 10}, "IT", 1, "Test", {100, 100}, "Test"} respectively: {object, string, integer, string, object, string} I have tried declaring it as list of objects or using Tuple(Of Object, String, Integer, String, Object, String) but when I give them the values, "Array initializer has too few dimensions" error occurs. The class where the variable is declared: Public Class SignatureResponse Public signature As Tuple(Of Object,