Here you can find the source of charToUpperOrLower(String string, int pos, boolean upper)
Parameter | Description |
---|---|
string | a parameter |
pos | a parameter |
upper | if set to true, the char is set to upper case; if set to false, the char is set to lower case |
public static String charToUpperOrLower(String string, int pos, boolean upper)
//package com.java2s; /**//w w w. j a v a 2 s . c om * Copyright 2015 SPeCS Research Group. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. under the License. */ public class Main { /** * Puts the given char to upper (true) or lower (false) case * * @param string * @param pos * @param upper * if set to true, the char is set to upper case; if set to false, the char is set to lower case * @return */ public static String charToUpperOrLower(String string, int pos, boolean upper) { if (pos < 0 || pos >= string.length()) { throw new StringIndexOutOfBoundsException(pos); } String ret = string.substring(0, pos); if (upper) { ret += string.substring(pos, pos + 1).toUpperCase(); } else { ret += string.substring(pos, pos + 1).toLowerCase(); } ret += string.substring(pos + 1); return ret; } }