I might be going the long way around and hopefully I can explain this without code as at the minute the code is all over the place.
What I want is a string
static String locationOneStr = new String ("res/.png");
static StringBuilder locationOneStrBuilder = new StringBuilder(locationOneStr);
That contains a base form of the URL where I want to call to later.
The code that comes later finds the number residing at position 0 or 'locationOne' and a switch choses which code to utilize: if it is a 0 it inserts 0 before the .png if its a 1 it inserts a 1 etc.
public static StringBuilder locationOneNumber(StringBuilder forCharConv, StringBuilder locationOneStrBuilder) {
char localChar = forCharConv.charAt(0);
switch (localChar) {
case '0':
BpmCalcFrame.locationOneStrBuilder.insert(3,"0");
System.out.println("Zero");
break;
/*
*
* Other Cases Omitted
*/
default:
System.out.println("There is no valid input!");
break;
}
return;
}
The problem I have is that a switch has to return something. However the jframe I am using as a test environment is expecting a String for the URL.
JLabel locationOne = new JLabel("Image 1");
locationOne.setBackground(Color.WHITE);
locationOne.setIcon(new ImageIcon(ArrayComparison.locationOneNumber(forCharConv, locationOneStrBuilder)));
locationOne.setBounds(172, 45, 36, 68);
contentPane.add(locationOne);
I am using StringBuilder as Strings eat up memory, but if I have to convert the StringBuilder to a String it defeats the point of using the StringBuilder
Am I going about this the wrong way or do I really have to convert back to a String? This would mean I will be making on average 2 new objects a second for the entire of the program's lifecycle.
Is there a way of making an instance of the StringBuilder as a String without creating a new object?